• asp.net让FCKEditor上传图片到动态指定的目录


    比如我们在编辑一篇文章时,,我们总希望FCK的上传图片上传到我们指定的目录,比如按时间.或按ID等等 ;
     
     
     需要指定路径就得找到FCK上传文件时组合路径的地方.
     
    拿到FCK的.net的源码:FredCK.FCKeditorV2
     
    打开源码目录FileBrowser下的Config.cs文件
     
    就可以看到组合路径方式:
     

      1. internal void LoadConfig()  
      2. {  
      3. DefaultSettings();  
      4.  
      5. // Call the setConfig() function for the configuration file (config.ascx).  
      6. SetConfig();  
      7.  
      8. // Look for possible UserFilesPath override options.  
      9. string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];  
      10.  
      11. string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];  
      12. if (!string.IsNullOrEmpty(userFilesPath))  
      13. {  
      14. userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ] + userFilesPath.Trim('/');  
      15. }  
      16.  
      17. // Session  
      18. if (string.IsNullOrEmpty(userFilesPath))  
      19. {  
      20. userFilesPath = Session["FCKeditor:UserFilesPath"] as string;  
      21. }  
      22. // Application  
      23. if ( userFilesPath == null || userFilesPath.Length == 0 )  
      24. userFilesPath = Application[ "FCKeditor:UserFilesPath" ] as string;  
      25.  
      26. // Web.config file.  
      27. if ( userFilesPath == null || userFilesPath.Length == 0 )  
      28. userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ];  
      29.  
      30. // config.asxc  
      31. if ( userFilesPath == null || userFilesPath.Length == 0 )  
      32. userFilesPath = this.UserFilesPath;  
      33.  
      34. if ( userFilesPath == null || userFilesPath.Length == 0 )  
      35. userFilesPath = DEFAULT_USER_FILES_PATH;  
      36.  
      37. // Check that the user path ends with slash ("/")  
      38. if ( !userFilesPath.EndsWith( "/" ) )  
      39. userFilesPath += "/";  
      40.  
      41. userFilesPath = string.IsNullOrEmpty(hostname) ? userFilesPath : hostname.TrimEnd('/') + userFilesPath;  
      42. userFilesPath = this.ResolveUrl( userFilesPath );  
      43.  
      44. this.UserFilesPath = userFilesPath;  
      45. }  

    相信看这段代码不是难事
     
    string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];
       
      string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];
     
    这二项是我加上的..我们就是通过URL来动态传递路径的
    因为url传路径不安全.我们还是保留FCK的web.config配置路径的方式...只是我们会在配置:FCKeditor:UserFilesPath目录下再生成我们规则的路径
     
    比如:FCKeditor:UserFilesPath配置为:/WebData/
    而我们传的路径为 userfilespath=2010/08/09
    那么上传文件的路径就是webdata/2010/08/09...这是我们可以动态赋值给FCK的
     
     
     做到这里还不够..我们得给FCK加个属性可以让我们动态设置路径;
     
    打开源码中的:FCKeditor.cs
     
    找到代码块:#region Configurations Properties
     
    加一个属性在此代码块中:

      1. [Category("Configurations")]  
      2. public string FileMidPath  
      3. {  
      4. set { ImageBrowserURL = this.EditorPath + "/filemanager/browser/default/browser.html?Type=Image&Connector=" +  
      5. this.EditorPath + "/filemanager/connectors/aspx/connector.aspx?userfilespath=" + value; }  
      6. }  

     
     ImageBrowserURL 就是FCK图片浏览的地址;userfilespath就是我们动态设定的路径
     
    现在使用就简单了;
     
    在页面中加上FCK后;在pageload中赋给其路径:这个路径随便你给..GUID等都行.
     

      1. protected void Page_Load(object sender, EventArgs e)  
      2. {  
      3. FckContent.FileMidPath = "2010/08/09";  
      4. }  

    看看效果:
     
     
     至此完成路径重写了
     
    当然你可以改得更自由..不过安全也很重要

    源码下载:http://www.jiamaocode.com/Cts/1237.html

    http://www.phpfans.net/ask/quiz1/2418992482.html

    www.aitaowang8.com

  • 相关阅读:
    获取当前季的js
    C#获取文件大小
    SQL Server 2005 Express Edition 傻瓜式安装
    SET XACT_ABORT ON
    Resignation letter
    Exchange Web Services Managed API 1.0 入门
    Please let us know in case of any issues
    33条C#、.Net经典面试题目及答案
    c# 修饰词public, protected, private,internal,protected的区别
    EXEC DTS
  • 原文地址:https://www.cnblogs.com/activities/p/2195809.html
Copyright © 2020-2023  润新知