Hello Friends,

I have developed a windows application using C#, its installed on

C:/program files/application folder/application.exe

I have not used Data base so i have used files (CSV/TXT) for storing data, there is many types of files generated by application and some application setting variables are also stored in a file named

C:/program files/application folder/Application Settings folder/applicationSettings.data

(encrypted Text file) application used these settings to read paths other files and some other settings, this application also have the feature to print document/images using

PrintDocument printDocumentObj= new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintPageEventHandlerFunc);
.....

application prints files successfully but if I select other printer like

\\othersystem\printername

this also prints the document/image but after printing application can't find the application settings file which is stored in

C:/program files/application folder/Application Settings folder/applicationSettings.data

i have tried to debug the program and found that the application searching applicationSettings.data file in wrong location

\\othersystem\\Application Settings folder\applicationSettings.data 
which should be this...
C:/program files/application folder/Application Settings folder/applicationSettings.data

I am not sure why the path changes after selecting the other printer even i have have used constant variable for storing the path of applicationSettings.data

thanks in advance
Rahul

I have tried to define the path variable of ApplicationSettings.data

const string _ApplicationSettingFolder = @"C:\program files\application folder\Application Settings folder\Application Settings folder";
And
const string _ApplicationSettingFolder = @".\Application Settings folder";
And
String strAppDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
const string _ApplicationSettingFolder = strAppDir + @"\Application Settings folder";

All three types are not working... :(

its seems that the Application.ExecutablePath changes after selecting other printer.

Edited 5 Years Ago by katarey: n/a

If you know that printing can change the current directory just remember it
before printing and restore it after printing:

string temp = Directory.GetCurrentDirectory();
......................do whatever
Directory.SetCurrentDirectory(temp);

This article has been dead for over six months. Start a new discussion instead.