I 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 a string so SaveAs()
doesn't compile.
Why I am using string? Because when I am using public HttpPostedFileBase imagefile {get;set;}
it shows a null value in the controller.
Model
public string imagePath { get;set; } // contains the name of the image
public string imageFile { get;set; } // contains string bytes
C#
byte[] data = Convert.FromBase64String(Quot[i].imageFile.Replace("data:image/jpeg;base64,", ""));
Image img;
MemoryStream ms = new MemoryStream(data, 0, data.Length);
ms.Write(data, 0, data.Length);
img = Image.FromStream(ms, true);
string fileName = Path.GetFileNameWithoutExtension(Quot[i].imagePath);
string extension = Path.GetExtension(Quot[i].imagePath);
fileName = fileName + DateTime.Now.ToString("dd/MM/yyyy") + extension;
Quot[i].imagePath = "~/AppFiles/Images/" + fileName;
fileName = Path.Combine(HttpContext.Current.Server.MapPath("~/AppFiles/Images/"), fileName);
Quot[i].imageFile.SaveAs(fileName);