Hi Guys, i have a code to display an image in a picturebox called MemberPics. this image is also saved into a folder D:\\pictures. My problem is eventhough the image is saved successfully, am not able to retrieve it in another form. I always have FileNotFoundException even when I can physically see the file in the folder. please can anyone help me out. this is the code to display and save the image
private void btnpics_Click(object sender, EventArgs e)
{
OpenFileDialog openFD = new OpenFileDialog();
//string chosen_file = "";
openFD.Title = "Insert an image ";
openFD.InitialDirectory = "c:";
openFD.FileName = "";
openFD.Filter = "JPEG Image|*.jpg|GIF Image|*.gif|PNG Image|*.png";
if (openFD.ShowDialog() == DialogResult.Cancel)
{
MessageBox.Show("Operation cancelled !");
}
else
{
/*chosen_file = openFD.FileName;
MemberPics.Image = Image.FromFile(chosen_file);
//MemberPics.Image.Save("d:\\Pictures\\Chosen.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
MemberPics.Image.Save("d:\\Pictures\\chosen_file", System.Drawing.Imaging.ImageFormat.Jpeg);*/
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.ShowDialog();
//string fileName = System.IO.Path.GetFileName(ofd.FileName);
fileName = System.IO.Path.GetFileName(ofd.FileName);
System.IO.File.Copy(ofd.FileName, "D:\\Pictures\\" + fileName);
MemberPics.Image = Image.FromFile("D:\\Pictures\\" + fileName);
}
Later when i use this, the FileNotFoundException is thrown at me after successfuly saving a user info and i want to load it into another picturebox
display.Image = Image.FromFile("D:\\Pictures\\" + fileName);