Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have to load the picture to pictureBox.
C#
imagePath="D:\\Temp\\name1.jpg";
pictureBox1.Load(imagePath);

Error:

Could not find file 'D:\Temp\name1.jpg'.

how to check condition image is there or not in particular path("D:\\Temp\\name1.jpg";).
or
how to avoid this error?

Regards,
Karthikeyan,
Bangalore.
Posted
Updated 26-Sep-12 18:50pm
v2

Hi,

try this code:
C#
string imagePath = "D:\\Temp\\name1.jpg";
if(System.IO.File.Exists(imagePath))
  pictureBox1.Load(imagePath);
 
Share this answer
 
Comments
pkarthionline 27-Sep-12 0:55am    
Thanks.It is working.
try like this way

C#
string Imgpath= @"D:\temp\name1.jpg";
 
Share this answer
 
the best is to use Try and Catch:

C#
try
{
    pictureBox1.Load(@"C:\Documents and Settings\Administrator\Desktop\NewFolder\qqq.jpg");
}
    catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900