Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

.net core 上传文件Demo

旗木卡卡罗特 2019-12-02 21:18:00 阅读数:57 评论数:0 点赞数:0 收藏数:0

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("上传成功");
}

 

版权声明
本文为[旗木卡卡罗特]所创,转载请带上原文链接,感谢
https://www.cnblogs.com/zhouyg2017/p/11973357.html