开发者

Using OpenFileDialog w/ a relative path as initialDirectory

开发者 https://www.devze.com 2023-04-04 15:35 出处:网络
I\'d like to g开发者_如何转开发ive the appropriate value to Initial directory, so it would open the folder (called \"Images\") which I created in my project.

I'd like to g开发者_如何转开发ive the appropriate value to Initial directory, so it would open the folder (called "Images") which I created in my project. I must use a relative path, so my program works not depending on the computer I work . But the problem is I don't know how to access this folder...

Does anyone know how to solve this problem?


use:

openFileDialog.InitialDirectory = Path.Combine(Application.StartupPath,
@"YourSubDirectoryName");

Edit: or try this if you prefer... are you in windows forms?

openFileDialog.InitialDirectory = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Application.ExecutablePath), @"YourSubDirectoryName");

Edit 2 for WPF:

string path = System.Reflection.Assembly.GetExecutingAssembly().Location;

... from the Microsoft Forums...

0

精彩评论

暂无评论...
验证码 换一张
取 消