文件上传

string path = Server.MapPath("~/Content/img/");//设定上传的文件路径
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//判断是否已经选择上传文件
HttpPostedFileBase file = Request.Files["file"];
string filenName = file.FileName;
string filepath = path + filenName;
file.SaveAs(filepath);//上传路径
//然后你就可以用filepath新增到数据库里面了。
return Content("");

posted @ 2017-09-15 10:10  风里的人  阅读(85)  评论(0)    收藏  举报