FCKEditor在.net的使用

FCKeditor一款开放源码的优秀的HTML文本编辑器,它在ASP.NET下一般的安装和使用方法如下:

1、下载FckEditor 2.6.3,它主要包括核心文件。

2、下载FckEditor 2.6.3 .Net ,包括ASP.NET的DLL文件,并且解压到任意目录。

3、解压FckEditor 2.6.3 压缩包,将文件夹FCKeditor复制到网站的根目录,这里以ASP.NET 2.0的test项目为例,将其复制到test的根目录,并且在根目录下新建uploads目录用来存放编辑器上传得文件。

4、修改js配置.打开FCKeditor目录下的fckconfig.js文件,将FCKConfig.DefaultLanguage的值改为zh-cn使其的界面语言改变为简体中文,_FileBrowserLanguage和_QuickUploadLanguage的值都改为aspx。可选的修改如下,可以修改编辑器的skin,将FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' 的default可以该为office2003或者silver。保存修改,关闭文件。

5、配置web.config.
打开工程的Web. Config文件,修改appSettings元素,配置如下:

<appSettings>

<add key="FCKeditor:BasePath" value="~/FCKeditor/"/>

<add key="FCKeditor:UserFilesPath" value="/你的项目名称/uploads" />
//例如:我的解决方案名为test,那么这里就是"/test/uploads".

</appSettings>

设置了FCKeditor:BasePath后就不用再每次使用FCKeditor实例时指定BasePath属性了,FCKeditor:UserFilesPath则是制定我们所有上传的文件的所在目录。你也许会问为什么要设置成/test/uploads这样而不是~/uploads,因为FCKeditor使用这个值来返回你上传后的文件的相对路径到客户端,~/uploads的形式是ASP.NET在服务可以编译解释的,但是在客户端的静态就不懂这是什么了。如果使用~/uploads后,那么所有上传文件的返回路径都是~/uploads形式的,你就会得到这样的链接http://~/uploads/Image/logo.gif这样的链接解果就是路径为找到。所以才要我们上述那样设置,这是在开发阶段,如果在工程完成后发布时请记住把/test/uploads改成/uploads,道理不说大家也明白,开发阶段VS2005在运行项目时的URL是http://localhost/项目名称/的形式,发布后在Server上建立站点,跟路径就是http://www.abc.com/的形式了,所以发布后一定要改过来。这些地方是在使用FCKeditor2.6.3+ASP.NET2.0时经常发错误而又莫名其所云的地方。

6、在项目中引用刚才解压的FCKeditor.NET压缩包里的FredCK.FCKeditorV2.dll文件。具体位置是 FCKeditor.Net_2.6.3/bin/release/FredCK.FCKeditorV2.dll

7、注册用户控件.打开test项目的default.aspx页面,在

程序代码
<%@ Page Language="C#" MasterPageFile="~/Weblog.master" AutoEventWireup="true" CodeFile="article.aspx.cs" Inherits="article" Title="Test FckEditor" %>

下面加入以下代码

程序代码
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

然后就可以在default.aspx页面使用这个控件了:

程序代码
<fckeditorv2:fckeditor id="FCKeditor" runat="server" Width="580px" EnableXHTML="true" EnableSourceXHTML="true" basepath="~/FCKeditor/" height="500px"></fckeditorv2:fckeditor>

8、如何取得编辑器中的文本。
该控件有个属性是value,它就是获得编辑器中的文本的。

9、FCKeditor控件的属性和事件。
具有的属性列表如下:

AutoDetectLanguage
BaseHref
BasePath
ContentLangDirection
CustomConfigurationsPath
Debug
DefaultLanguage
EditorAreaCSS
EnableSourceXHTML
EnableViewState
EnableXHTML
FillEmptyBlocks
FontColors
FontFormats
FontNames
FontSizes
ForcePasteAsPlainText
ForceSimpleAmpersand
FormatIndentator
FormatOutput
FormatSource
FullPage
GeckoUseSPAN
Height
ID
ImageBrowserURL
LinkBrowserURL
PluginsPath
runat
SkinPath
StartupFocus
StylesXMLPath
TabSpaces
ToolbarCanCollapse
ToolbarSet
ToolbarStartExpanded
UseBROnCarriageReturn
Value
Visible
Width

具体的事件列表如下:

OnDataBinding
OnDisposed
OnInit
OnLoad
OnPreRender
OnUnload

FCKeditor出现"this connector is disabled Please check the"editor/filemanager/connectors/aspx/config.aspx"错误的解决办法

解决办法:

打开editor/filemanager/connectors/aspx/config.ascx修改CheckAuthentication()方法,返回true

C# code

private bool CheckAuthentication()
{
// WARNING : DO NOT simply return "true". By doing so, you are allowing
// "anyone" to upload and list the files in your server. You must implement
// some kind of session validation here. Even something very simple as...
//
//        return ( Session[ "IsAuthorized" ] != null && (bool)Session[ "IsAuthorized" ] == true );
//
// ... where Session[ "IsAuthorized" ] is set to "true" as soon as the
// user logs in your system.

        return true;
}

为了安全性的考虑可以在这里加入用户验证,根据用户权限,确定是否有权限上传文件.

posted on 2009-04-14 11:00  9who  阅读(1746)  评论(2编辑  收藏  举报

导航