asp.net FckEditor配置

一、设置上传文件语言

把FCKeditor根目录下面的fckconfig.js文件里

var _FileBrowserLanguage      = 'aspx ' ;      // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage      = 'aspx ' ;      // asp | aspx | cfm | lasso | php

二、在asp.net中动态设置上传图片的路径?

1.在javascript中修改FCKConfig.ImageBrowserURL的值,修改方式如下:
FCKConfig.ImageBrowserURL += "?Path=要上传的文件路径";
如:要把文件上传到站点根目录的UploadFile文件夹中,则设置为:
FCKConfig.ImageBrowserURL += "?Path=/UploadFile";
2.在"editor\filemanager\browser\default\connectors\aspx\connector.aspx"文件最后中增加以下程序:

1<script runat="server" language="C#">
2 protected override void OnInit(EventArgs e)
3 ...{
4if( Request.QueryString["Path"]==null )...{
5 Session["FCKeditor:UserFilesPath"] = "/UpLoadFiles/"; //设置默认值
6}else...{
7 Session["FCKeditor:UserFilesPath"] = Request.QueryString["Path"];
8}
9 }
10</script>

3. 若是固定上传图片的位置就简单了:
在"editor\filemanager\browser\default\connectors\aspx\config.ascx"文件最后中修改以下程序:
public override void SetConfig()
    {
        // SECURITY: You must explicitly enable this "connector". (Set it to "true").
        Enabled = CheckAuthentication();

        // URL path to user files.
        UserFilesPath = "~/Book/Upload/FCKEditor/"; //改成自己想固定的位置就可以了
}


三、
删除不必要的文件

从官方下载下来的FCKEditor2.6大小有3.61M(解压后),其实有很多文件对于只用ASP.NET的来讲是不需要的,可以删除不必要的文件:

1.根目录下除editor目录、fckconfig.js、fckeditor.js fckstyles.xml fcktemplates.xml 这几个保留,其余的全部删除

2.editor\filemanager\connectors目录中除aspx目录外全部删除

3.editor\lang目录中除en.js、zh.js 、zh-cn.js外全部删除

4.删除_samples目录,当然如果你想看示例,就不要删除这个目录了。

四、风格设置
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;
我喜欢这个风格。当然还有office2003和默认的可以选择。

五、添加常用字体
FCKConfig.FontNames        = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

六、打开和关闭文件上传功能
有三个文件跟这个开关有关系,一个是js文件,两个是asp文件,前者关闭后界面中不出现相关窗口或按钮,后者关闭后相关功能不可用。
首先是fckconfig.js文件,以下内容设为true为开,false则为关。
文件浏览和浏览中上传功能:

程序代码
FCKConfig.LinkBrowser = false ;
FCKConfig.ImageBrowser = false ;
FCKConfig.FlashBrowser = false ;

七、在ToolbarSets中可设置显示的工具
可去掉About

配置选项:

AutoDetectLanguage=true/false 自动检测语言

Basehref="" _fcksavedurl="""" 相对链接的基地址

ContentLangDirection="ltr/rtl" 默认文字方向

ContextMenu=字符串数组,右键菜单的内容

CustomConfigurationsPath="" 自定义配置文件路径和名称

Debug=true/false 是否开启调试功能,这样,当调用FCKDebug.Output()时,会在调试窗中输出内容

DefaultLanguage="" 缺省语言

EditorAreaCss="" 编辑区的样式表文件

EnableSourceXHTML=true/false 为TRUE时,当由可视化界面切换到代码页时,把HTML处理成XHTML

EnableXHTML=true/false 是否允许使用XHTML取代HTML

FillEmptyBlocks=true/false 使用这个功能,可以将空的块级元素用空格来替代

FontColors="" 设置显示颜色拾取器时文字颜色列表

FontFormats="" 设置显示在文字格式列表中的命名

FontNames="" 字体列表中的字体名

FontSizes="" 字体大小中的字号列表

ForcePasteAsPlainText=true/false 强制粘贴为纯文本

ForceSimpleAmpersand=true/false 是否不把&符号转换为XML实体

FormatIndentator="" 当在源码格式下缩进代码使用的字符

FormatOutput=true/false 当输出内容时是否自动格式化代码

FormatSource=true/false 在切换到代码视图时是否自动格式化代码

FullPage=true/false 是否允许编辑整个HTML文件,还是仅允许编辑BODY间的内容

GeckoUseSPAN=true/false 是否允许SPAN标记代替B,I,U标记

IeSpellDownloadUrl=""下载拼写检查器的网址

ImageBrowser=true/false 是否允许浏览服务器功能

ImageBrowserURL="" 浏览服务器时运行的URL

ImageBrowserWindowHeight="" 图像浏览器窗口高度

ImageBrowserWindowWidth="" 图像浏览器窗口宽度

LinkBrowser=true/false 是否允许在插入链接时浏览服务器

LinkBrowserURL="" 插入链接时浏览服务器的URL

LinkBrowserWindowHeight=""链接目标浏览器窗口高度

LinkBrowserWindowWidth=""链接目标浏览器窗口宽度

Plugins=object 注册插件

PluginsPath="" 插件文件夹

ShowBorders=true/false 合并边框

SkinPath="" 皮肤文件夹位置

SmileyColumns=12 图符窗列数

SmileyImages=字符数组 图符窗中图片文件名数组

SmileyPath="" 图符文件夹路径

SmileyWindowHeight 图符窗口高度

SmileyWindowWidth 图符窗口宽度

SpellChecker="ieSpell/Spellerpages" 设置拼写检查器

StartupFocus=true/false 开启时FOCUS到编辑器

StylesXmlPath="" 设置定义CSS样式列表的XML文件的位置

TabSpaces=4 TAB键产生的空格字符数

ToolBarCanCollapse=true/false 是否允许展开/折叠工具栏

ToolbarSets=object 允许使用TOOLBAR集合

ToolbarStartExpanded=true/false 开启是TOOLBAR是否展开

UseBROnCarriageReturn=true/false 当回车时是产生BR标记还是P或者DIV标记


解决FCKEditor上传时中文文件名的方法

主要是修改文件frmUpload.html文件.用记事本打开frmUpload.html,另存为UTF-8格式即可.


上传文件自动改名:打开FileBrowser文件夹中的FileWorkerBase.cs文件。
  1. sFileName = System.IO.Path.GetFileName( oFile.FileName );
  2. sFileName = this.SanitizeFileName( sFileName );
  3. string sExtension = System.IO.Path.GetExtension( oFile.FileName );
  4. sExtension = sExtension.TrimStart( '.' );
修改为:
  1. sFileName = System.IO.Path.GetFileName( oFile.FileName );
  2. sFileName = this.SanitizeFileName( sFileName );
  3. string sExtension = System.IO.Path.GetExtension(oFile.FileName );
  4. sExtension = sExtension.TrimStart( '.' ); Random ro = new Random();
  5. sFileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() +
  6. DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ateTime.Now.Second.ToString() + ro.Next(99, 1000) + "." + sExtension;

本文原创转载请注明出处
项目需要在线HTML编辑器,就选择了FCKeditor,目前最新是2.5Bate,不过稳定点定还是选了2.4.3,而.net的控件还是2.2没变过 [smile] ,大概如何使用见我之前的“FCKeditor 2.3 在ASP.NET中文件上传路径的设置”,关于它的配置如:界面布局啊什么的网上去搜索下,太多了,就不写了 [smile]
FCKeditor在web.config中有多项设置:

  1. <appSettings>  
  2. <!--FCKeditor设置(主要是以下两项)-->  
  3. <!--FCKeditor编辑器路径-->  
  4. <add key="FCKeditor:BasePath" value="/FCKeditor/"/>  
  5. <!--FCKeditor用户附件上传路径-->  
  6. <add key="FCKeditor:UserFilesPath" value="/Resources/TempUpload/"/>  
  7. </appSettings>  

  用户登录后通过FCKeditor上传文件则要放置在用户共用上传路径“/Resources/UserUpload/”+“用户邮箱地址”, 如“/Resources/UserUpload/user@gmail.com”。FCKeditor.net获取上传路径文件是:FileWorkerBase.cs,打开找到以下部分

  1. protected string UserFilesPath   
  2.      {   
  3.       get  
  4.        {   
  5.         if ( sUserFilesPath == null )   
  6.          {   
  7.           // 第一回从Application["FCKeditor:UserFilesPath"] 中读取,如果没有尝试其它方式   
  8.            sUserFilesPath = (string)Application["FCKeditor:UserFilesPath"] ;   
  9.   
  10.           // 第二回从Session["FCKeditor:UserFilesPath"] 中读取,如果没有尝试其它方式   
  11.           if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )   
  12.            {   
  13.              sUserFilesPath = (string)Session["FCKeditor:UserFilesPath"] ;   
  14.                
  15.             // 第三回从web.config中读取,如果没有尝试其它方式   
  16.             if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )   
  17.              {   
  18.                sUserFilesPath = System.Configuration.ConfigurationSettings.AppSettings["FCKeditor:UserFilesPath"] ;   
  19.                  
  20.               // 第四回从DEFAULT_USER_FILES_PATH(这个变量在同文件中)中读取,如果没有尝试其它方式   
  21.               if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )   
  22.                  sUserFilesPath = DEFAULT_USER_FILES_PATH ;   
  23.   
  24.               // 第五回从网址参数ServerPath中读取   
  25.               if ( sUserFilesPath == null || sUserFilesPath.Length == 0 )   
  26.                {   
  27.                  sUserFilesPath = Request.QueryString["ServerPath"] ;   
  28.                }   
  29.   
  30.              }   
  31.            }   
  32.   
  33.           // Check that the user path ends with slash ("/")   
  34.           if ( ! sUserFilesPath.EndsWith("/") )   
  35.              sUserFilesPath += "/" ;   
  36.          }   
  37.         return sUserFilesPath ;   
  38.        }   
  39.      }  

  从上面的注释可以看到用户上传路径的顺序,只要在页面加载的时候设置下Session["FCKeditor:UserFilesPath"]就可以设置FCKeditor上用户上传路径了

  1. protected void Page_Load(object sender, EventArgs e)   
  2. {   
  3. if (!Page.IsPostBack)   
  4. Session["FCKeditor:UserFilesPath"] = "用户上传路径";   
  5. }  

  (我在配置的时候关闭了文件浏览,只提供文件快速上传)但是在使用的时候如果“Resources/UserUpload/user@gmail.com”中的user@gmail.com路径没创建,上传中FCKeditor它不会创建,也导致了文件无法上传成功,那就需要再修改FCKeditor.net项目中的Uploader.cs文件,添加一段文件夹存在的检测代码,如果不存在用户指定的文件夹侧创建一个

  1. // Get the uploaded file name.   
  2. string sFileName = System.IO.Path.GetFileName( oFile.FileName ) ;   
  3.   
  4. int iCounter = 0 ;   
  5.   
  6. //景裔添加   
  7. //检查上传目录是否已经被创建   
  8. //开始==========================================   
  9. //检查当前完整路径是否存在,不存在则开始逐级轮询检查,不存则就创建   
  10. if (!System.IO.Directory.Exists(UserFilesDirectory))   
  11. {   
  12. string[] tempDirectorys = UserFilesDirectory.Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries);
  13. string tempDirectory = string.Empty;
  14. for (int i = 0; i < tempDirectorys.Length; i++)
  15. {
  16. tempDirectory += tempDirectorys[i] + "\\";
  17. if (!System.IO.Directory.Exists(tempDirectory))
  18. System.IO.Directory.CreateDirectory(tempDirectory);
  19. }
  20. }
  21. //结束==========================================
  22. while ( true )
  23. {
  24. string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;
  25. if ( System.IO.File.Exists( sFilePath ) )
  26. {
  27. iCounter++ ;
  28. sFileName =
  29. System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +
  30. "(" + iCounter + ")" +   
  31. System.IO.Path.GetExtension( oFile.FileName ) ;   
  32.   
  33. iErrorNumber = 201 ;   
  34. }   
  35. else  
  36. {   
  37. oFile.SaveAs( sFilePath ) ;   
  38.   
  39. sFileUrl = this.UserFilesPath + sFileName ;   
  40. break ;   
  41. }   
  42. }  
这样就基本解决了多用户分文件夹上传图片的问题,不过也有缺陷的地方,就是当用户Session超时的时候,用户再使用浏览器上传文件就不会按 照指定用户文件夹上传来了,分析这个情况可以得出:这个时候用户通过编辑器上传的文件也就是对编辑器内容作出了修改,但是因为Session超时了,所以 可以把做出的修改视作无效,既然修改无效,那用户上传的文件也是没用的,所在我在web.config中又设置了个默认文件上传位置,所有无效文件都会上 传到这里,那个回清理的时候也方便多了 [lol] 不知道哪位大虾还有更好的办法。
http://hi.baidu.com/xuguoyi/blog/item/5adbd55cdc284e46faf2c063.html
原文地址:https://www.cnblogs.com/chenbg2001/p/1364288.html