public ActionResult FileUpload()
{
string filetype = "UpFile";
var file = this.Request.Files[0];
string savedFileName = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UpFiles");
savedFileName = System.IO.Path.Combine(savedFileName, filetype);
string filename = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "." + file.FileName.Substring(file.FileName.LastIndexOf(".") + 1);
savedFileName = System.IO.Path.Combine(savedFileName, System.IO.Path.GetFileName(filename));
file.SaveAs(savedFileName);
string tmpRootDir = Server.MapPath(System.Web.HttpContext.Current.Request.ApplicationPath.ToString());//获取程序根目录
string fileurl = savedFileName.Replace(tmpRootDir, ""); //转换成相对路径
fileurl = "/" + fileurl.Replace(@"\", @"/");
return Json(new { success = true },"text/html");
}
代码下载: https://files.cnblogs.com/cube/UpLoad.rar