随笔 - 52  文章 - 0 评论 - 196 trackbacks - 9
<2010年9月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

昵称:使名扬
园龄:8年1个月
粉丝:1
关注:0

搜索

 
 

常用链接

随笔档案

最新评论

阅读排行榜

评论排行榜

推荐排行榜

以前一直用lion的。因为现在写一个西班牙语的网站,FCKeditor 有现成的多国语言库,就改用FCKeditor了。

1.先从http://www.fckeditor.net/download 下载FCKeditor.Net_2.6.4.zip   FCKeditor_2.6.6.zip

解压FCKeditor.Net_2.6.4.zip,提取FCKeditor.Net_2.6.4\bin\Release\2.0中的FredCK.FCKeditorV2.dll,添加引用。再加到左边的控件栏里吧。名字就叫FCKeditor

 

2.

安装配置

    1、拷贝 "FredCK.FCKeditorV2.dll" 到BIN目录。拷贝fckeditor文件夹到站点跟目录;

 

 

上传图片的配置

------------------------------------------------------------

配置上传路径

1.见web.config


      2.编辑FCKeditor"editor"filemanager"connectors"aspx"config.aspx 中修改

 private bool CheckAuthentication()
      {
        return true;
       }

 

    2、用文本编辑器打开fckeditor/fckconfig.js文件,开始对编辑器进行配置;

        var _FileBrowserLanguage = 'asp' ;

        var _QuickUploadLanguage = 'asp' ;

        改为

        var _FileBrowserLanguage = 'aspx' ;

        var _QuickUploadLanguage = 'aspx' ;

    3、配置webConfig选项;

代码
  <appSettings>
    
<add key="FCKeditor:BasePath" value="~/FCKeditor/"/>
    
<add key="FCKeditor:UserFilesPath" value="~/userfiles"/>
  
</appSettings>


    
<system.web>
...
      
<identity impersonate="true"/><!--Access数据库写权限 -->
       <pages validateRequest="false" /><!-- 省得每个页面加HTML免过滤了-->

...
    
</system.web>

 

 

 

 

   4、在页面中使用控件

        添加页面指令:<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

        添加一个控件:<FCKeditorV2:FCKeditor ID="FCKeditor2" runat="server" DefaultLanguage="zh-cn" Height="400px"></FCKeditorV2:FCKeditor>

使用示例

    自定义按钮

        1、用文本编辑器打开fckeditor/fckconfig.js文件

        2、拷贝FCKConfig.ToolbarSets["Basic"] = [['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink','-','About']] ;

        改为:

        FCKConfig.ToolbarSets["Myself"] = [['Bold','Italic','-','OrderedList','UnorderedList']] ;

        3、设置控件的ToolbarSet属性。<FCKeditorV2:FCKeditor ID="FCKeditor2" ToolbarSet="Myself" runat="server"></FCKeditorV2:FCKeditor>

 

------------------------------------------------------------

    换肤

        系统提供了三种皮肤:default,office2003,silver; 在控件上设置SkinPath="editor/Skins/Default/";也可以通过程序完成设置

    其它设置

        

        在编辑器域内可以使用Tab键。(1为是,0为否) FCKConfig.TabSpaces = 0 ; 改为FCKConfig.TabSpaces = 1 ;

示例代码

fckeditor.aspx

<%@ Page Language="C#" AutoEventWireup="true" ValidateRequest="false" CodeFile="fckeditor.aspx.cs" Inherits="fckeditor" %>

<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <br />

         全部按钮<br />

<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server" >

        </FCKeditorV2:FCKeditor>

        <br />

         基本按钮<br />

        <FCKeditorV2:FCKeditor ID="FCKeditor2" ToolbarSet="Basic"   runat="server"></FCKeditorV2:FCKeditor>

        <br />

         精简按钮<br />

        <FCKeditorV2:FCKeditor ID="FCKeditor3" ToolbarSet="Basic2" runat="server">

        </FCKeditorV2:FCKeditor>

        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />&nbsp;

        <br />

        <a href="fckeditor/_samples/default.html">浏览更多示例</a>

        </div>

    </form>

</body>

</html>

 

 

----

多国语言对照表

fckeditor\editor\lang里的js名字-全名

 

  af  : 'Afrikaans',
  ar  : 'Arabic',
  bg  : 'Bulgarian',
  bn  : 'Bengali/Bangla',
  bs  : 'Bosnian',
  ca  : 'Catalan',
  cs  : 'Czech',
  cy  : 'Welsh',
  da  : 'Danish',
  de  : 'German',
  el  : 'Greek',
  en  : 'English',
  'en-au' : 'English (Australia)',
  'en-ca' : 'English (Canadian)',
  'en-gb' : 'English (United Kingdom)',
  eo  : 'Esperanto',
  es  : 'Spanish',
  et  : 'Estonian',
  eu  : 'Basque',
  fa  : 'Persian',
  fi  : 'Finnish',
  fo  : 'Faroese',
  fr  : 'French',
  'fr-ca' : 'French (Canada)',
  gl  : 'Galician',
  gu  : 'Gujarati',
  he  : 'Hebrew',
  hi  : 'Hindi',
  hr  : 'Croatian',
  hu  : 'Hungarian',
  is  : 'Icelandic',
  it  : 'Italian',
  ja  : 'Japanese',
  km  : 'Khmer',
  ko  : 'Korean',
  lt  : 'Lithuanian',
  lv  : 'Latvian',
  mn  : 'Mongolian',
  ms  : 'Malay',
  nb  : 'Norwegian Bokmal',
  nl  : 'Dutch',
  no  : 'Norwegian',
  pl  : 'Polish',
  pt  : 'Portuguese (Portugal)',
  'pt-br' : 'Portuguese (Brazil)',
  ro  : 'Romanian',
  ru  : 'Russian',
  sk  : 'Slovak',
  sl  : 'Slovenian',
  sr  : 'Serbian (Cyrillic)',
  'sr-latn' : 'Serbian (Latin)',
  sv  : 'Swedish',
  th  : 'Thai',
  tr  : 'Turkish',
  uk  : 'Ukrainian',
  vi  : 'Vietnamese',
  zh  : 'Chinese Traditional',
  'zh-cn' : 'Chinese Simplified'

 

--------------------------------

 

实现FCKeditor 多用户分文件夹上传图片等附件

 

FROM:http://blog.breakn.net/article.asp?id=388

 项目需要在线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.  
  23. while ( true )  
  24. {  
  25. string sFilePath = System.IO.Path.Combine( this.UserFilesDirectory, sFileName ) ;  
  26.  
  27. if ( System.IO.File.Exists( sFilePath ) )  
  28. {  
  29. iCounter++ ;  
  30. sFileName =   
  31. System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +  
  32. "(" + iCounter + ")" +   
  33. System.IO.Path.GetExtension( oFile.FileName ) ;   
  34.   
  35. iErrorNumber = 201 ;   
  36. }   
  37. else  
  38. {   
  39. oFile.SaveAs( sFilePath ) ;   
  40.   
  41. sFileUrl = this.UserFilesPath + sFileName ;   
  42. break ;   
  43. }   
  44. }  

 

  这样就基本解决了多用户分文件夹上传图片的问题,不过也有缺陷的地方,就是当用户Session超时的时候,用户再使用浏览器上传文件就不会按照指定用户文件夹上传来了,分析这个情况可以得出:这个时候用户通过编辑器上传的文件也就是对编辑器内容作出了修改,但是因为Session超时了,所以可以把做出的修改视作无效,既然修改无效,那用户上传的文件也是没用的,所在我在web.config中又设置了个默认文件上传位置,所有无效文件都会上传到这里,那个回清理的时候也方便多了

 

posted on 2010-09-20 14:34 使名扬 阅读(380) 评论(0) 编辑 收藏