zeeshan akram

zeeshan akram

  • 1.4k
  • 325
  • 18.2k

How to Save image File in Folder.

Oct 15 2018 3:05 PM
want to save image path in the database, I am using string type image not save in folder but image name also saved in the database. i am using string so SaveAs giving error.
 
why I am using string? because when I am using public httppostfilebase image file {get;set;} show null value in controller .
 
imagePath: this variable contains string bytes image file: this variable contain the name of the image
 
Any expert here to resolve my issue, and tell me what is the problem in my code.
 
Model
  1. public string imagePath { get;set; } public string imageFile { get;set; }  
C#
  1. byte[] data = Convert.FromBase64String(Quot[i].imageFile.Replace("data:image/jpeg;base64,"""));  
  2. Image img; MemoryStream ms = new MemoryStream(data, 0, data.Length);  
  3. ms.Write(data, 0, data.Length);  
  4. img = Image.FromStream(ms, true);  
  5. string fileName = Path.GetFileNameWithoutExtension(Quot[i].imagePath);  
  6. string extension = Path.GetExtension(Quot[i].imagePath);  
  7. fileName = fileName + DateTime.Now.ToString("dd/MM/yyyy") + extension;  
  8. Quot[i].imagePath = "~/AppFiles/Images/" + fileName;  
  9. fileName = Path.Combine(HttpContext.Current.Server.MapPath("~/AppFiles/Images/"), fileName);  
  10. Quot[i].imageFile.SaveAs(fileName); // Problem in this line due to imageFile string show error SaveAs 

Answers (2)