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?

3

1 Answer 1

2

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

string path = Path.GetDirectoryName(openFD.FileName);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.