Bhavesh Vankar

Bhavesh Vankar

  • 762
  • 1.1k
  • 87.3k

Capture image Again if image not currect

Aug 28 2020 7:23 AM
i want to capture image again if image not proper in c# using webcam into web application. but below error is generate while recapture image. how to solve this error.
 
Additional information: The process cannot access the file 'C:\VisiterManagment\VisiterManagment\CapturedImage\Image.jpg' because it is being used by another process.
 
i am also deleting existing file using file exist but not working kindly please help me.
 
here is my c# code
  1. string FileName = Path.GetFileName("~/CapturedImage/Image.jpg");  
  2. if (File.Exists(Path.GetFileName(FileName)))  
  3. {  
  4. File.Delete(FileName);  
  5. }  
  6. if (!this.IsPostBack)  
  7. {  
  8. if (Request.InputStream.Length > 0)  
  9. {  
  10. using (StreamReader myreader = new StreamReader(Request.InputStream))  
  11. {  
  12. string myhexString = Server.UrlEncode(myreader.ReadToEnd());  
  13. //string myimagePath = string.Format("~/CapturedImage/" + DateTime.Now.ToString("dd-MM-yy hh-mm-ss") + ".jpg");  
  14. string myimagePath = string.Format("~/CapturedImage/Image.jpg");  
  15. File.WriteAllBytes(Server.MapPath(myimagePath), ConvertHexToBytes(myhexString));  
  16. Session["CapturedImage"] = ResolveUrl(myimagePath);  
  17. }  
  18. }  
  19. }  

Answers (2)