简体   繁体   English

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

[英]C#, WPF - OpenFileDialog in project path

Im making a WPF App. 我正在制作WPF应用。 What i want to do is open OpenFileDialog property in path in project. 我想做的是在项目路径中打开OpenFileDialog属性。

My code: 我的代码:

OpenFileDialog openPicture = new OpenFileDialog();
openPicture.Filter = "Image files|*.bmp;*.jpg;*.gif;*.png;*.tif";
openPicture.FilterIndex = 1;

if (openPicture.ShowDialog() == true) 
{
    string filepath = openPicture.FileName;
}

I want to acces ExampleImages folder in my project: 我想访问我项目中的ExampleImages文件夹:

在此处输入图片说明

The only solution that i found is using this ( Another question ): 我发现的唯一解决方案是使用此( 另一个问题 ):

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

But it seems like Application.StartupPath is hide in using System.Windows.Forms and i cant acces it in my WPF app. 但似乎Application.StartupPath隐藏在using System.Windows.Forms ,我无法在WPF应用程序中访问它。 Can you explain me, how to force OpenFileDialog to open into my project folder? 您能解释一下,如何强制OpenFileDialog打开我的项目文件夹吗?

Try 尝试

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

Note, that you should use this only during development. 请注意,您仅应在开发期间使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM