문제

i have created a form with FileBrowse control to load 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

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top