我正在制作WPF应用。我想做的是在项目的路径中打开OpenFileDialog
属性。
我的代码:
OpenFileDialog openPicture = new OpenFileDialog();
openPicture.Filter = "Image files|*.bmp;*.jpg;*.gif;*.png;*.tif";
openPicture.FilterIndex = 1;
if (openPicture.ShowDialog() == true)
{
string filepath = openPicture.FileName;
}
我想访问我项目中的ExampleImages
文件夹:
我发现的唯一解决方案是使用此(Another question):
openPicture.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName");
但是似乎Application.StartupPath
隐藏在using System.Windows.Forms
中,我无法在我的WPF应用程序中添加它。您能解释一下如何强制OpenFileDialog
打开我的项目文件夹吗?
答案 0 :(得分:0)
尝试
Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"..\\..\\ExampleImages"))
请注意,只应在开发过程中使用它。