我正在制作一个 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在我的项目中访问文件夹:我发现的唯一解决方案是使用这个(另一个问题):openPicture.InitialDirectory = Path.Combine(Path.GetDirectoryName(Application.StartupPath), "FolderName");但它似乎Application.StartupPath隐藏起来using System.Windows.Forms,我无法在我的 WPF 应用程序中访问它。你能解释一下,如何强制OpenFileDialog打开我的项目文件夹?
1 回答
心有法竹
TA贡献1866条经验 获得超5个赞
尝试
Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"..\\..\\ExampleImages"))
请注意,您应该仅在开发期间使用它。
- 1 回答
- 0 关注
- 255 浏览
添加回答
举报
0/150
提交
取消