C#,WPF-项目路径中的OpenFileDialog

时间:2018-08-31 08:19:25

标签: c# wpf file

我正在制作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文件夹:

enter image description here

我发现的唯一解决方案是使用此(Another question):

openPicture.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName");

但是似乎Application.StartupPath隐藏在using System.Windows.Forms中,我无法在我的WPF应用程序中添加它。您能解释一下如何强制OpenFileDialog打开我的项目文件夹吗?

1 个答案:

答案 0 :(得分:0)

尝试

Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"..\\..\\ExampleImages"))

请注意,只应在开发过程中使用它。