FCKeditor 在ASP.Net 中的使用说明[转贴]
来源:互联网 发布:js中format函数 编辑:程序博客网 时间:2024/04/28 15:51
FCKeditor 是一个运行在浏览器上的 JavaScript应用程序。他可以不依赖任何服务器端语言运行。不过,更好的使用方法是你使用一种服务器端语言来调用他。
在ASP.Net 中,有一个现成的工具包可以让你把FCKeditor 作为一个WebForms控件使用。这个工具包叫FCKeditor.Net。
要在你的 ASP.Net web 页面中使用他,请按照以下步骤执行。
前提条件
在进行以下几步前,你必须已经下载并且安装了最新版本的FCKeditor编辑器工具包(将他COPY到你的网站)。FCKeditor.Net工具包并不包含FCKeditor编辑器的代码。(将编辑器JavaScript代码放到你网站的/FCKeditor/目录)。你能从下面的地址下载到编辑器:
http://sourceforge.net/project/showfiles.php?group_id=75348&package_id=75845
第一步
确保编辑器已经在你网站的 "/FCKeditor/"目录里。现在,你需要下载FCKeditor ASP.Net 控件的DLL文件到你的页面。你能在下面的地址找到最新的版本:
http://sourceforge.net/project/showfiles.php?group_id=75348&package_id=137125
第二步
在下载的ZIP文件中包含控件的源代码和一个已经编译好的文件("bin/Release/FredCK.FCKeditorV2.dll")。大多少情况下,你并不需要对源代码做任何改变。你仅仅需要在你的项目中引用编译好的DLL文件,引用有2个方法:
- 手动复制FredCK.FCKeditorV2.dll 文件到你网站的"bin"目录
- 在你的Visual Studio.Net项目中按右键并选择“添加引用”,从你保存FredCK.FCKeditorV2.dll 文件的地方选择他。
- 你也可以直接在Visual Studio.Net工具箱中包含这个控件,在工具箱中右键,选择“添加项”,然后,选择FredCK.FCKeditorV2.dll。
- 确保你已经有了最新的DLL文件版本。
第三步
现在就可以在你的网站上使用他了,新建一个ASP.Net页面,在页面上创建一个实例,有2个方法:
- 把控件从工具箱中拖到你的页面(如果你已经在“第二步”中把他加到你的工具箱)
- 在你的ASP.Net页面顶部包含以下代码:
<%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
并且在<FORM runat="server">中添加控件的标签:
<FCKeditorV2:FCKeditor id="FCKeditor1" BasePath="~/FCKeditor/" runat="server" />
注意: BasePath属性所指定的目录就是FCKeditor 所在的目录
全部代码如下
<%@ Page ValidateRequest="false" Language="VB" AutoEventWireup="false" %>
<%@ Register TagPrefix="FCKeditorV2" Namespace="FredCK.FCKeditorV2" Assembly="FredCK.FCKeditorV2" %>
<html>
<head>
<title>FCKeditor - Sample</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form runat="server">
<FCKeditorV2:FCKeditor id="FCKeditor1" BasePath="~/FCKeditor/" runat="server" />
<br />
<input type="submit" value="Submit" runat="server" />
</form>
</body>
</html>
文件浏览和上传
为了方便上传文件和图片到服务器,FCKeditor拥有文件管理和快速上传功能。
FCKeditor的这个功能依赖于服务器端的语言。你只需要为你使用的那种语言做简单的设置。为了在ASP.Net中使用,你要打开FCKeditor目录中的fckconfig.js文件,找到_FileBrowserLanguage和 _QuickUploadLanguage,并将他们的值设置为'aspx' 。
你的网站必须有上传文件的权限,还要预先设置好上传目录。默认情况下, FCKeditor.Net会在网站的根目录下查找UserFiles 目录,并把所有文件都放到这里,所以要先建好这个目录 。
注意: 需要给予ASPNET和/或者 IUSR_<ComputerName>用户对UserFile目录的文件/目录的写和创建权限。
示范
你可以在FCKeditor.Net 工具包的"_samples/aspx"目录中找到一些告诉你如何使用的示范文件。把这个目录复制到FCKeditor安装的同一个目录就可以使用了。
最小安装示范
这是一个假设的在ASP.Net网站中使用FCKeditor的情况
我们可以看到,这个网站包括:
- FredCK.FCKeditorV2.dll 文件,从FCKeditor.Net 工具包中复制到网站根目录中的bin目录里。 (查看 "第一、第二步")
- FCKeditor 目录,编辑器的JavaScript代码(来自FCKeditor工具包). (查看 "前提条件")
- UserFiles 目录,放置用户上传文件的地方
- MyPage.aspx 页,包含上面演示如何使用编辑器的代码。 (查看 "第三步")
小技巧
你可以在web.config 配置文件中设置默认的UserFiles路径,这样,在你网站里使用的所有FCKeditor 编辑器都可以使用这个设置:
<appSettings>
<add key="FCKeditor:UserFilesPath" value="/Wherever/Directory/" />
</appSettings>
ASP.Net 1.1 和 2.0
在使用FCKeditor 的页面,需要把ValidateRequest属性为false:
<%@ Page Language="VB" Inherits="FredCK.FCKeditorV2.FileBrowserConnector" AutoEventWireup="false" ValidateRequest="false" %>
这是因为由编辑器建立的一些输入会被.Net Framework认为有危险。
ASP.Net 2.0 和主题
如果你正在使用Asp.net 2.0 和主题:你必须打开\editor\filemanager\upload\aspx\upload.aspx和、\editor\filemanager\browser\default\connectors\aspx\connector.aspx 并且在第一行添加或者修改Theme="":
<%@ Page Language="VB" Inherits="FredCK.FCKeditorV2.FileBrowserConnector" AutoEventWireup="false" Theme="" %>
在代码中修改UserFilesPath
如果你想修改用户上传文件的路径,你并不需要动态加载控件,但你需要在page init中做一些操作,(并不是在page load 中)。下面是一个例子:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Session("FCKeditor:UserFilesPath") = "~/App_Images/" & _teamName
End Sub
在代码中动态添加编辑器
把Base path 设置在 web.config文件中:
例如,如果下面是FCKeditor 所在目录"c:/inetpub/wwwroot/virtualdir/FCKeditor/",这样添加:
<add key="FCKeditor:BasePath" value="~/FCKeditor/" />
可以使用session 来设置UserFilesPath的路径,需要在你添加控件前设置session 变量。
Session("FCKeditor:UserFilesPath") = "/virtualdir/userfiles/"
可以使用request 对象来设置BasePath。假设当前路径是: "http://<host>/FCKEditor/"。
FCKeditor1.BasePath = Request.ApplicationPath + "/FCKEditor/";
添加控件到页面:
Dim fckeditor As New FredCK.FCKeditorV2.FCKeditor
fckeditor.ImageBrowserURL = "http://localhost/virtualdir/FCKeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/aspx/connector.aspx"
fckeditor.ID = "dynamicname"
fckeditor.Value = "the text you want in the FCK editor"
fckeditor.SkinPath = "skins/silver/"
fckeditor.ToolbarSet = "Default"
myForm.Controls.Add(fckeditor)
- FCKeditor 在ASP.Net 中的使用说明[转贴]
- FCKeditor 在ASP.Net 中的使用说明(翻译)
- FCKeditor 在ASP.Net 中的使用说明
- FCKeditor 在ASP.Net 中的使用说明
- FCKeditor 在ASP.Net 中的使用说明
- FCKeditor 在ASP.Net 中的使用说明
- FCKeditor 在ASP.Net 中的使用说明
- FCKeditor 在ASP.Net 中的使用说明
- FCKeditor 在ASP.Net 中的使用说明
- FCKEditor 在ASP.NET中的使用
- FCKEditor在ASP.NET中的使用
- FCKeditor在asp.net中的用法
- FCKeditor在Asp.Net中的配置
- FCKeditor在asp.net中的用法
- FCKeditor在ASP.NET中的配置方法
- FCKeditor在asp.net中的用法
- Fckeditor在asp.net中的使用方法
- FCKEditor 在 jsp中的使用说明
- 用js实现的刷新页面的代码
- modelsim中testbench的编写总结
- 将socks代理转换成http代理
- Esper 中的模式匹配 (Pattern Match) ----事件模式概述
- C/C++中堆栈区别详细解释
- FCKeditor 在ASP.Net 中的使用说明[转贴]
- js sleep函數
- ResourceCursorAdapter
- 循环和递归的问题
- 20款Notepad++插件下载和介绍
- 首批最佳骑行路线揭晓
- 模态窗口(showModalDialog)标题丢失或无效问题
- C++程序设计语言--第六章:表达式和语句
- JDK里面的hash算法