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

How are you getting the path to your applicationSettings.data file?
Is this a hard coded text path like this appdatapath = @".\Application Settings folder\applicationSettings.data"; ?
Or perhaps you use Environment.CurrentDirectory as the base path?

If so perhaps you should consider the following
Get Application Directory [C#]
and
MSDN How to: Get the Application Directory.

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.

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);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.