3
Answers

Speed up retrieve image into picturebox

I'm currently working on windows form application which allow user to retrieve image after searching at textbox. The problem is the image is load very slow. How can I overcome this problem to speed up the loading? If anyone has suggestions for a faster way to retrieve these images, it would be greatly appreciated. Here is my code:
 
  1. string baseFolder = @"\\\\jun01\\hr\\photo";  
  2.   string imgName =  "*" + textBoxEmplNo.Text  + "*.jpg";  
  3.   
  4.   //Bool to see if file is found after checking all  
  5.   bool fileFound = false;  
  6.   
  7.   DirectoryInfo di = new DirectoryInfo(baseFolder);  
  8.   foreach (var file in di.GetFiles(imgName, SearchOption.AllDirectories))  
  9.   
  10.    {  
  11.     pictureBox1.Visible = true;  
  12.     pictureBox1.Image = Image.FromFile(file.FullName);  
  13.   
  14.     fileFound = true;  
  15.     break;  
  16.    }  
  17.   
  18.     if (!fileFound)  
  19.    {  
  20.     pictureBox1.Visible = true;  
  21.     pictureBox1.Image = Image.FromFile(@"\\\\jun01\\hr\\photo\\No-image-  
  22.     found.jpg");  
  23.    }  
 
Answers (3)