zoukankan      html  css  js  c++  java
  • Mvc3文件(或图片)上传

     public JsonResult AddProDoc(ProjectDoc doc)
            {
                try
                {
    ///文件
                    HttpPostedFileBase file = Request.Files["File"];
    ///图片
                    //WebImage image = WebImage.GetImageFromRequest("");
                    if (file != null)
                    {
                        var filename = Path.GetFileName(file.FileName);
                        var fileExtension = filename.Substring(filename.LastIndexOf("."));
                        var buildName = DateTime.Now.ToString("yyyyMMddhhmmss") + fileExtension;
                        var savepath = Path.Combine(Server.MapPath("~/Content/Upload/Prodocuments"), buildName);
                        file.SaveAs(savepath);
    //image.Save((savepath, forceCorrectExtension: false));
                                           return Json(new { success = true, Message = "文档添加成功!" }, "text/html", JsonRequestBehavior.AllowGet);
                    }
                    return Json(new { success = false, Message = "您没有上传任何文档!" }, "text/html", JsonRequestBehavior.AllowGet);
                }
                catch (Exception e)
                {
                    return Json(new { success = false, Message = "文档添加失败!" }, "text/html", JsonRequestBehavior.AllowGet);
                }
            }

    前提是要在页面上设置enctype="multipart/form-data",否则会报错

  • 相关阅读:
    IfcQuantityWeight
    IfcPhysicalComplexQuantity
    IfcBinary
    大服务器
    DFF环境配置
    Java程序设置为开机自启动
    IfcArbitraryProfileDefWithVoids
    定位日志
    blazor相关资料
    老人与海 电影
  • 原文地址:https://www.cnblogs.com/a546558309/p/2593511.html
Copyright © 2011-2022 走看看