public string UploadFile()
{
string result="上传成功"
try{
//接收上传后的文件
HttpPostedFile file = Context.Request.Files["imgPath4"]
//获取文件的保存路径
string uploadPath = HttpContext.Current.Server.MapPath("~/_data/Files")
string fileEx = Path.GetExtension(file.FileName)//文件的格式
string dtStr = file.FileName.Replace(fileEx, "_") + DateTime.Now.ToString("yyyyMMddhhmmss")
//判断上传的文件是否为空
if (file != null)
{
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath)
}
//保存文件
file.SaveAs(HttpContext.Current.Server.MapPath("~/_data/Files/" + dtStr + fileEx))
filePath = HttpContext.Current.Server.MapPath("~/_data/Files/" + dtStr + fileEx)
}
}
catch (Exception ex)
{
result="上传失败"
}
return result
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)