CKEditor与CKFinder
1、下载
CKEditor:http://ckeditor.com/download
CKFinder:http://cksource.com/ckfinder/download,下载ASP.NET版
2、放入项目中:
3、另开一个VS重新打开ckfinder/_source/CKFinder.Net.sln,编译后,将Bin/Debug/CKFinder.dll复制出来到WebApplication2下。
4、删除ckfinder文件夹下_source文件夹。
5、修改ckfinder下config.ascx文件:
public override 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 on your system. //此处原来是return false; return true; }
6、建立一个新的WebForm.aspx页面。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication2.WebForm1" ValidateRequest="false" %> <!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></title> <script type="text/javascript" src="/PlugIn/ckeditor/ckeditor.js"></script> <script type="text/javascript" src="/PlugIn/ckfinder/ckfinder.js"></script> </head> <body> <form id="form1" runat="server"> <div> <textarea id="ckeditor1" name="ckeditor1" runat="server"><p>编辑器内容</p></textarea> <script type="text/javascript"> var editor = CKEDITOR.replace('ckeditor1'); // 创建编辑器 CKFinder.setupCKEditor(editor, '/PlugIn/ckfinder/'); // 为编辑器绑定"上传控件" </script> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /> </div> </form> </body> </html>
7、为防止提交html不成功,该页面设置在第一行ValidateRequest="false"。
在Web.config:
<system.web> <compilation debug="true" targetFramework="4.0" /> <httpRuntime requestValidationMode="2.0" /> </system.web>
8、服务器端代码(测试):
protected void Button1_Click(object sender, EventArgs e) { Label1.Text = ckeditor1.Value; }
9、说明:ckeditor负责格式编辑;ckfinder负责上传文件处理;上传的文件默认是存放位置在ckfinder/userfiles