Default Application running path
-
Hi, I have an application which runs well until an open dialog box is accessed by the user. What happens is that is appears when the user selects the file to open it changes the default directory for the application and the application tries to access a file in the new directory rether than the application default directory. For example. The default directory is C:\Program Files\App The file path the user selects is C:Temp I have an .xml file in C:\Program Files\App which is accessed fine before the open dialog but after the open dialog the program crashes because it is looking for the .xml file in the C:Temp directory and not the C:\Program Files\App directory. What I want to do is force the program to always look for this file in the C:\Program Files\App directory without hard coding the path. Any ideas and help are appreciated. Regards Stephen McAllister
-
Hi, I have an application which runs well until an open dialog box is accessed by the user. What happens is that is appears when the user selects the file to open it changes the default directory for the application and the application tries to access a file in the new directory rether than the application default directory. For example. The default directory is C:\Program Files\App The file path the user selects is C:Temp I have an .xml file in C:\Program Files\App which is accessed fine before the open dialog but after the open dialog the program crashes because it is looking for the .xml file in the C:Temp directory and not the C:\Program Files\App directory. What I want to do is force the program to always look for this file in the C:\Program Files\App directory without hard coding the path. Any ideas and help are appreciated. Regards Stephen McAllister
-
Hi, I have an application which runs well until an open dialog box is accessed by the user. What happens is that is appears when the user selects the file to open it changes the default directory for the application and the application tries to access a file in the new directory rether than the application default directory. For example. The default directory is C:\Program Files\App The file path the user selects is C:Temp I have an .xml file in C:\Program Files\App which is accessed fine before the open dialog but after the open dialog the program crashes because it is looking for the .xml file in the C:Temp directory and not the C:\Program Files\App directory. What I want to do is force the program to always look for this file in the C:\Program Files\App directory without hard coding the path. Any ideas and help are appreciated. Regards Stephen McAllister
StephenMcAllister wrote: I have an .xml file in C:\Program Files\App which is accessed fine before the open dialog but after the open dialog the program crashes because it is looking for the .xml file in the C:Temp directory and not the C:\Program Files\App directory. Assuming that C:\Program Files\App is the path where your executable resides you can use the Application.StartupPath[^] property. Best regards Dennis
-
Hi, I have an application which runs well until an open dialog box is accessed by the user. What happens is that is appears when the user selects the file to open it changes the default directory for the application and the application tries to access a file in the new directory rether than the application default directory. For example. The default directory is C:\Program Files\App The file path the user selects is C:Temp I have an .xml file in C:\Program Files\App which is accessed fine before the open dialog but after the open dialog the program crashes because it is looking for the .xml file in the C:Temp directory and not the C:\Program Files\App directory. What I want to do is force the program to always look for this file in the C:\Program Files\App directory without hard coding the path. Any ideas and help are appreciated. Regards Stephen McAllister
Follow Dennis' link to the Application.StartupPath(). The problem your having is that your assuming that the current directory will never change when you app is open. This is simply not the case. As you've found out, it can change at any time. When you code file paths, NEVER use just a filename. ALWAYS prefix your filepaths with a complete path specification. You can use the Application.StartupPath() to return the directory path that your .EXE was launched from. Then use the Path class' Combine() method to build a full path specification to your .XML file. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome