我試圖用IFormFile
..這是我的HTML顯示MVC中保存的文件與點網核心
<input type="file" asp-for="lstAttachments" accept="application/pdf,application" multiple/>
其中lstAttachments
是IFormFile
public IEnumerable<IFormFile> lstAttachments { get; set; }
我收集上傳多個文件將文件保存到某個文件夾,然後將文件夾保存到數據庫表中。 這工作得很好。
var filePath = "" ;
Guid guid;
List<userattachmentsdetail> attachmentsToInsert = new List<userattachmentsdetail>();
userattachmentsdetail newAttachment;
foreach (var file in userDetail.lstAttachments)
{
guid = Guid.NewGuid();
filePath = hostingEnv.WebRootPath + [email protected]"\uploadedFiles" + [email protected]"\{guid}_{file.FileName}";
using (FileStream fs = System.IO.File.Create(filePath))
{
file.CopyTo(fs);
fs.Flush();
}
newAttachment = new userattachmentsdetail();
newAttachment.FileName = file.FileName;
newAttachment.FilePath = filePath;
attachmentsToInsert.Add(newAttachment);
}
在編輯模式下,我從表中獲取的名稱和路徑,並試圖加載文件
這是我的查詢從表中獲取文件路徑數據
Select FileName, FilePath from userattachmentsdetail uad
這裏我正在將數據存儲到列表中
List<userattachmentsdetail> lstFiles = grid.Read<UserFiles>().ToList();
lstFiles
包含所有文件,但現在我被卡住,如何共同將此數據轉換/複製到IFormFile
集合(lstAttachments)。
編輯文件的內容可以是PDF,文本或DOCX。
做的文件是什麼樣子? IFormFile是什麼樣的? – Alex
對不起,沒有? –
這些文件的內容是什麼,併發布您的代碼爲IFormFile,它的實現。有隔靴搔癢的信息在這個問題上,甚至開始幫助 – Alex