0

Im making a WPF App. What i want to do is open OpenFileDialog property in path in project.

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:

enter image description here

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. Can you explain me, how to force OpenFileDialog to open into my project folder?

  • 1
    Possible duplicate of [how to get current application path in wpf](https://stackoverflow.com/questions/10926506/how-to-get-current-application-path-in-wpf) (`System.AppDomain.CurrentDomain.BaseDirectory` or `Directory.GetCurrentDirectory()`) – Cee McSharpface Aug 31 '18 at 08:25

1 Answers1

0

Try

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

Note, that you should use this only during development.

ChristianMurschall
  • 1,621
  • 15
  • 26