Bhavesh Vankar

Bhavesh Vankar

  • 761
  • 1.1k
  • 88k

Recapture Image error

Sep 7 2020 5:57 AM
By Recapture image occur error "The process cannot access the file because its used by another process."
my code is below  i try to delete existing file but not successed. 
  1. [WebMethod()]  
  2.        public static bool SaveCapturedImage(string data)  
  3.        {  
  4.            string fileName = DateTime.Now.ToString("dd-MM-yy hh-mm");  
  5.            //string fileName2 = DateTime.Now.ToString("dd-MM-yy hh-mm");  
  6.            //Convert Base64 Encoded string to Byte Array.  
  7.            //if (File.Exists(fileName2))  
  8.            //{  
  9.            //    File.Delete(fileName2);  
  10.            //}  
  11.            //else  
  12.            //{  
  13.                byte[] imageBytes = Convert.FromBase64String(data.Split(',')[1]);  
  14.                //Save the Byte Array as Image File.  
  15.                string filePath = HttpContext.Current.Server.MapPath(string.Format("~/CapturedImage/{0}.jpg", fileName));  
  16.                File.WriteAllBytes(filePath, imageBytes);  
  17.                return true;  
  18.            //}