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

  • 相关阅读:
    接口和抽像类
    java中FastJson的json类型转换
    可参考的源码
    @Autowired注解和静态属性
    IDEA中,将项目加入maven管理。
    关于.idea未上传导致不能显示项目文件结构的问题
    Master-Worker模式
    Future模式
    了解Queue
    ConcurrentMap与CopyOnWrite容器
  • 原文地址:https://www.cnblogs.com/ruiyuan/p/11404314.html
Copyright © 2011-2022 走看看