c#中文件上传(1)

                
这个是.aspx页面中用来上传文件的接口,适用于App接口

int
maxlength = 1024 * 1024 * 3;//3M picPath = Server.MapPath("........."); HttpFileCollection postfile = Context.Request.Files; for (int i = 0; i < postfile.Count; i++) { HttpPostedFile file = postfile[i]; if (!CheckType(GetExtension(file.FileName).Substring(1))) { r.success = false; r.message = "文件类型不正确,上传失败!"; } if (file.ContentLength > maxlength) { r.success = false; r.message = "上传文件的大小超过了3MB的最大容量!请压缩后再上传!"; } string strNewPath = DateTime.Now.ToShortDateString().Replace("-", "") + DateTime.Now.ToLongTimeString().Replace(":", "") + DateTime.Now.Millisecond + GetExtension(file.FileName); file.SaveAs(picPath +"/"+ strNewPath); strNewPath = strNewPath.Replace("\", "/"); urlPath = picServer + strNewPath; originalname = GetOriginalName(file.FileName); if (originalname == "") { originalname = file.FileName; } string newName = GetOriginalName1(strNewPath); file.SaveAs(Server.MapPath(".") + "/" + Path.GetFileName(file.FileName)); }
原文地址:https://www.cnblogs.com/ly77461/p/5772785.html