Reputation:
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?
Upvotes: 0
Views: 1573
Reputation: 29
Try to make use of the Path.GetDirectoryName
method.
Example:
string path = Path.GetDirectoryName(openFD.FileName);
Upvotes: 2