.net core 上传文件Demo

view:

<form method="post" enctype="multipart/form-data" action="@Url.Action("Upload")">
<input type="file" id="file" name="file"/> <button>提交</button>
</form>

  

controlller:

public IActionResult Upload()
{
var file = Request.Form.Files[];
if (file==null||file.Length==)
{
return Content("文件为空");
}
var pathBase = Directory.GetCurrentDirectory();
var uploadPath = Path.Combine(pathBase, "Upload");
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
string name = Guid.NewGuid().ToString() + file.FileName;
string filePath = Path.Combine(uploadPath,name);
using (var statem=System.IO.File.Create(filePath))
{
file.CopyTo(statem);
} return Content("上传成功");
}
上一篇:手机游戏渠道SDK接入工具项目分享(三)拨开云雾是个坑


下一篇:codeforces 3D . Least Cost Bracket Sequence 贪心