我正在使用Razor和C#在MS網站上進行文件上傳。ASP.NET Razor文件上傳
如果我有多個文件上傳按鈕,C#代碼如何知道上傳文件來自哪個按鈕?基於文件上傳的按鈕,我將把文件保存到特定的文件夾。
https://docs.microsoft.com/en-us/aspnet/web-pages/overview/data/working-with-files
@using Microsoft.Web.Helpers;
@{
var fileName = "";
if (IsPost) {
var fileSavePath = "";
var uploadedFile = Request.Files[0];
fileName = Path.GetFileName(uploadedFile.FileName);
fileSavePath = Server.MapPath("~/App_Data/UploadedFiles/" +
fileName);
uploadedFile.SaveAs(fileSavePath);
}
}
<!DOCTYPE html>
<html>
<head>
<title>FileUpload - Single-File Example</title>
</head>
<body>
<h1>FileUpload - Single-File Example</h1>
@FileUpload.GetHtml(
initialNumberOfFiles:1,
allowMoreFilesToBeAdded:false,
includeFormTag:true,
uploadText:"Upload")
@if (IsPost) {
<span>File uploaded!</span><br/>
}
</body>
</html>