c# FileBrowse changes path for the rest of my application
i have created a form with FileBrowse control to l开发者_Python百科oad a file from. the problem is, after i load a file the application looks for files in the path i'v selected instead of the 'Debug' directory (where files should be...)
how can i avoid it ? is it normal behavior ?
You can avoid it by not relying on the current directory being anything. Just consider what happens if you create a shortuct to your application, and change the startup directory.
If you want the directory where the application is why do you look for the current directory? You can get the directory of the application with the following:
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
If this is a Windows Forms application, you can get it much easier:
Application.StartupPath
Answered Here: Why does OpenFileDialog change my working directory?
And Here: Why the current working directory changes when use the Open file dialog in Windows XP ?
This beahviour is part of Windows Common Controls (OpenFileDialog
) and has nothing to do with your application configuration.
However, you can set the initial directory in your application.
Check the control for a property called RestoreDirectory. Is this set to True? If yes, try it as false.
精彩评论