zoukankan      html  css  js  c++  java
  • C#文件上传

     //var fileName = System.IO.Path.GetFileName(upload.FileName);
                //var filePhysicalPath = Server.MapPath("~/Content/" + fileName);//我把它保存在网站根目录的 upload 文件夹
                var fileName = Path.Combine(Request.MapPath("~/Content"),
                   Path.GetFileName(upload.FileName));
                upload.SaveAs(fileName);

                var url = "/Content/" + upload.FileName;
                var CKEditorFuncNum = System.Web.HttpContext.Current.Request["CKEditorFuncNum"];

                //上传成功后,我们还需要通过以下的一个脚本把图片返回到第一个tab选项
                return Content("<script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", "" + url + "");</script>");
          

     string fileExt = postFile.FileName.Substring(postFile.FileName.LastIndexOf(".") + 1); //文件扩展名,不含“.”
                        string newFileName = DateTime.Now.ToString("yyyyMMddHHmmssffff") + "." + fileExt; //随机生成新的文件名
                        string upLoadPath = "~/Picture/"; //上传目录相对路径
                        string fullUpLoadPath = Server.MapPath(upLoadPath);  //将路径转换成 物理路径
                        string newFilePath = upLoadPath + newFileName; //上传后的路径
                        postFile.SaveAs(fullUpLoadPath + newFileName);  //核心方法
                        return Json(new { success=true, message="", remark= "/Picture/" + newFileName });

  • 相关阅读:
    树形地铁系统[树的最小表示]
    156. 矩阵[二维的hash]
    兔子与兔子
    滑动窗口【单调队列入门题】
    【YBTOJ】生日相同
    【YBTOJ】移位包含
    【YBTOJ】【HDUOJ 3085】逃离噩梦
    【YBTOJ】立体推箱子
    【CodeForces 1408F】Two Different
    【Luogu P3338】[ZJOI2014]力
  • 原文地址:https://www.cnblogs.com/ruiyuan/p/11404314.html
Copyright © 2011-2022 走看看