使用具有相对路径作为initialDirectory的OpenFileDialog [英] Using OpenFileDialog w/ a relative path as initialDirectory

查看:640
本文介绍了使用具有相对路径作为initialDirectory的OpenFileDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给Initial目录提供适当的值,所以打开我在项目中创建的文件夹(称为Images)。
我必须使用相对路径,所以我的程序不依赖于我工作的电脑。
但问题是我不知道如何访问这个文件夹...

I'd like to give 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?

推荐答案

使用:

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

编辑:或尝试这个,如果你喜欢...你在Windows窗体?

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

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

为WPF编辑2

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

...从Microsoft论坛...

... from the Microsoft Forums...

这篇关于使用具有相对路径作为initialDirectory的OpenFileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆