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
- public string imagePath { get;set; } public string imageFile { get;set; }
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);