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)); }

 

posted @ 2016-08-15 14:20  ly77461  阅读(331)  评论(0编辑  收藏  举报