码迷,mamicode.com
首页 > Web开发 > 详细

文件上传

时间:2017-08-25 14:56:11      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:map   content   message   error   erro   try   return   uniq   cdb   

技术分享
            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

 

文件上传

标签:map   content   message   error   erro   try   return   uniq   cdb   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!