Multiple image upload using asp.net core 3.1

preview_player
Показать описание

#asp_net_core #multipe_image_upload
Рекомендации по теме
Комментарии
Автор

File is being copied but only last row inserted into database. Please provide solution.


#region File Upload

if (files != null)
{
Attachment oAttachment = new Attachment();
string CaseNo = oCaseInfo.ID;
string newCaseFilePath = + "\\wwwroot" + "\\uploads\\" + CaseNo;
if //directory create

foreach (var file in files)
{
if (file.Length > 0)
{
//Getting FileName
var fileName =

//Assigning Unique Filename (Guid)
var myUniqueFileName =

//Getting file Extension
var fileExtension = Path.GetExtension(fileName);

// concatenating FileName + FileExtension
var newFileName = String.Concat(myUniqueFileName, fileExtension);

oAttachment.CaseID = oCaseInfo.ID;
oAttachment.AttachmentName = fileName;
= myUniqueFileName + fileExtension;
oAttachment.SetupDate = DateTime.Now;
oAttachment.AttachmentPath = newCaseFilePath;

// Combines two strings into a path.
var filepath = newCaseFilePath + "\\" + newFileName;
//var filepath = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Images")).Root + $@"\{newFileName}";

using (FileStream fs =
{
file.CopyTo(fs);
fs.Flush();
}


}
}
}


#endregion

mazidulislamzahid