首页 > Web开发 > 详细

文件上传

时间:2017-08-25 14:51:27      阅读:270      评论:0      收藏:0      [点我收藏+]
技术分享
            string fileName = fileData.FileName;
            string path = System.Web.HttpContext.Current.Server.MapPath("~/UploadFile");
            string filePath = System.IO.Path.Combine(path, fileName);
            string newFileName=FileHelper.GetUniqueFileName(filePath);
            string newFilePath = System.IO.Path.Combine(path, newFileName);
            try
            {
                byte[] buf = new byte[fileData.ContentLength];
                Stream inputStream = fileData.InputStream;
                inputStream.Read(buf, 0, fileData.ContentLength);
                inputStream.Close();
                FileStream outputStream = new FileStream(newFilePath, FileMode.Create);
                outputStream.Write(buf, 0, buf.Length);
                outputStream.Close();
                return Json(new { error = 0, msg = "success", fileName = newFileName, fileUrl =  "/UploadFile/" + newFileName });
            }
            catch (Exception e)
            {
                return Json(new { error = 1, msg = e.Message });
            }
View Code

 

文件上传

原文:http://www.cnblogs.com/liandy0906/p/7427809.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!