比如我们在编辑一篇文章时,,我们总希望FCK的上传图片上传到我们指定的目录,比如按时间.或按ID等等 ;
需要指定路径就得找到FCK上传文件时组合路径的地方.
拿到FCK的.net的源码:FredCK.FCKeditorV2
打开源码目录FileBrowser下的Config.cs文件
就可以看到组合路径方式:
- internal void LoadConfig()
- {
- DefaultSettings();
-
-
- SetConfig();
-
-
- string hostname = System.Configuration.ConfigurationSettings.AppSettings["HostName"];
-
- string userFilesPath = HttpContext.Current.Request.QueryString["userfilespath"];
- if (!string.IsNullOrEmpty(userFilesPath))
- {
- userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ] + userFilesPath.Trim('/');
- }
-
-
- if (string.IsNullOrEmpty(userFilesPath))
- {
- userFilesPath = Session["FCKeditor:UserFilesPath"] as string;
- }
-
- if ( userFilesPath == null || userFilesPath.Length == 0 )
- userFilesPath = Application[ "FCKeditor:UserFilesPath" ] as string;
-
-
- if ( userFilesPath == null || userFilesPath.Length == 0 )
- userFilesPath = System.Configuration.ConfigurationSettings.AppSettings[ "FCKeditor:UserFilesPath" ];
-
-
- if ( userFilesPath == null || userFilesPath.Length == 0 )
- userFilesPath = this.UserFilesPath;
-
- if ( userFilesPath == null || userFilesPath.Length == 0 )
- userFilesPath = DEFAULT_USER_FILES_PATH;
-
-
- if ( !userFilesPath.EndsWith( "/" ) )
- userFilesPath += "/";
-
- userFilesPath = string.IsNullOrEmpty(hostname) ? userFilesPath : hostname.TrimEnd('/') + userFilesPath;
- userFilesPath = this.ResolveUrl( userFilesPath );
-
- this.UserFilesPath = userFilesPath;
- }
相信看这段代码不是难事
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
加一个属性在此代码块中:
- [Category("Configurations")]
- public string FileMidPath
- {
- set { ImageBrowserURL = this.EditorPath + "/filemanager/browser/default/browser.html?Type=Image&Connector=" +
- this.EditorPath + "/filemanager/connectors/aspx/connector.aspx?userfilespath=" + value; }
- }
ImageBrowserURL 就是FCK图片浏览的地址;
userfilespath就是我们动态设定的路径
现在使用就简单了;
在页面中加上FCK后;在pageload中赋给其路径:这个路径随便你给..GUID等都行.
- protected void Page_Load(object sender, EventArgs e)
- {
- FckContent.FileMidPath = "2010/08/09";
- }
看看效果:
至此完成路径重写了
当然你可以改得更自由..不过安全也很重要