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

我正在制作一个 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在我的项目中访问文件夹:

http://img.mukewang.com/61c6d43b00019d3002430204.jpg

我发现的唯一解决方案是使用这个(另一个问题):

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

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


蝴蝶刀刀
浏览 263回答 1
1回答

心有法竹

尝试Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"..\\..\\ExampleImages"))请注意,您应该仅在开发期间使用它。
打开App,查看更多内容
随时随地看视频慕课网APP