0

is there a way to get the image directory path after selecting in file dialog

example C:\Users\Admin\Desktop\IMG\pix200.jpg

i have a code that will open file dialog then after selecting Image and displaying Image in PictureBox i need to get the image location or path directory as i said earlier

private void student_Edit_PictureBox_Front_DoubleClick(object sender, EventArgs e)
    {
        OpenFileDialog openFD = new OpenFileDialog();
        openFD.Filter = "Bitmaps|*.bmp|jpeg|*.jpg";

        if (openFD.ShowDialog() == DialogResult.OK)
        {
            student_Picture_Edit.Image = Bitmap.FromFile(openFD.FileName);
            student_Edit_PictureBox_Front.Image = Bitmap.FromFile(openFD.FileName);

            //I want to get the directory path Picturebox.Imagelocation is not working for me
        }
    }

is there a solution for this?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 3
    This should solve your problem https://stackoverflow.com/questions/439007/extracting-path-from-openfiledialog-path-filename – Krivitskiy Grigoriy Dec 02 '19 at 13:45
  • 2
    Does this answer your question? [Extracting Path from OpenFileDialog path/filename](https://stackoverflow.com/questions/439007/extracting-path-from-openfiledialog-path-filename) – Kevin Dec 02 '19 at 13:49
  • The PictureBox will not know which path the image came from; so you need to store it when loading. – TaW Dec 02 '19 at 13:51

1 Answers1

2

Try to make use of the Path.GetDirectoryName method. Example:

string path = Path.GetDirectoryName(openFD.FileName);