天天看點

CKEditor和CKFinder在ASP.NET中的應用

CKEditor和CKFinder在ASP.NET中的應用,需要的朋友可以參考下。 CKEditor是新一代的FCKeditor,是一個重新開發的版本。CKEditor是全球最優秀的網頁線上文字編輯器之一,因其驚人的性能與可擴充性而廣泛的被運用于各大網站。而CKFinder是一個功能強大的ajax檔案管理器。其簡單的使用者界面使得各類使用者,不管是從進階專業人才,還是網際網路初學者,都夠直覺、快速學習的學習使用它。

網址:

CKEditor :http://ckeditor.com/

CKFinder :http://ckfinder.com/

CKEditor 的使用

準備工作

1. 下載下傳CKEditor并将其解壓到Web根目錄下

2. 精簡目錄:

_samples檔案夾(示例檔案,可以删除)

_source檔案夾(源程式檔案,可以删除)

changes.html(更新清單,可以删除)

install.html(安裝指向,可以删除)

license.html(使用許可,可以删除)

CKEditor的配置(config.js檔案)

詳細api參數見:http://docs.cksource.com/ckeditor_api/,我的預設配置

複制代碼 代碼如下:

// 自定義 CKEditor 樣式

CKEDITOR.editorConfig = function(config) {

//配置預設配置

config.language = 'zh-cn'; //配置語言

// config.uiColor = '#FFF'; //背景顔色

// config.width = 400; //寬度

// config.height = 400; //高度

// config.skin = 'v2'; //編輯器皮膚樣式

// 取消 “拖拽以改變尺寸”功能

// config.resize_enabled = false;

// 使用基礎工具欄

// config.toolbar = "Basic";

// 使用全能工具欄

config.toolbar = "Full";

//使用自定義工具欄

// config.toolbar =

// [

// ['Source', 'Preview', '-'],

// ['Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', ],

// ['Undo', 'Redo', '-', 'Find', 'Replace', '-', 'SelectAll', 'RemoveFormat'],

// ['Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', SpecialChar','PageBreak'],

// '/',

// ['Bold', 'Italic', 'Underline', '-', 'Subscript', 'Superscript'],

// ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'],

// ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'],

// ['Link', 'Unlink', 'Anchor'],

// '/',

// ['Format', 'Font', 'FontSize'],

// ['TextColor', 'BGColor'],

// ['Maximize', 'ShowBlocks', '-', 'About']

// ];

};

CKEditor 的應用

1. 在 aspx 頁面或者 master 模闆頁 <head> 标簽中加載 ckeditor.js:

  <!-- 載入 CKEditor JS 檔案 -->

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

2. 修改頁面的page指令ValidateRequest="false"

<%@ Page Language="C#" ValidateRequest="false" %>

3. 在<body>标簽中使用ckeditor:

<!-- 使用 ckeditor 必須定義 class="ckeditor" -->

<asp:TextBox ID="txtContent" class="ckeditor" TextMode="MultiLine"

Text='<%# Bind("info") %>' runat="server"></asp:TextBox>

4. 擷取或設定編輯器中的内容

//擷取編輯器中的内容

lblView.Text=Server.HtmlEncode( this.txtContent.Text);

//設定編輯器中的内容

//txtContent.Text = Server.HtmlDecode("<h1>設定内容</h1>");

CKFinder 的使用

準備工作

1. 下載下傳CKFinder的Asp.NET版,将其解壓到Web根目錄下

2. 複制/bin/Release目錄下的ckfinder.dll檔案至站點bin目錄

3. 精簡目錄:

_samples檔案夾(示例檔案,可以删除)

_source檔案夾(源程式檔案,可以删除)

CKFinder的配置

1. 打開 " \ckfinder\config.ascx ",為SetConfig方法中的 BaseUrl 指定預設路徑,如:

// 以userfiles 為預設路徑,其目錄下會自動生成images、flash等子目錄。

BaseUrl = " ~/ckfinder/userfiles/";

// NOTE:注意“ ~/ ”。

2. 與CKEditor內建

打開CKEditor目錄中的config.js檔案在function 函數中

複制代碼 代碼如下:

// 自定義 CKEditor 樣式

CKEDITOR.editorConfig = function(config) {

……

};

加入如下内容:

複制代碼 代碼如下:

// 在 CKEditor 中內建 CKFinder,注意 ckfinder 的路徑選擇要正确。

config.filebrowserBrowseUrl = location.hash + '/ckfinder/ckfinder.html';

config.filebrowserImageBrowseUrl = location.hash + '/ckfinder/ckfinder.html?Type=Images';

config.filebrowserFlashBrowseUrl = location.hash+'/ckfinder/ckfinder.html?Type=Flash';

config.filebrowserUploadUrl = location.hash + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files';

config.filebrowserImageUploadUrl = location.hash + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Images';

config.filebrowserFlashUploadUrl = location.hash + '/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Flash';

// config.filebrowserWindowWidth = '800';

// config.filebrowserWindowHeight = '500';

CKFinder的應用

1. 在工具欄中添加站點根目錄bin目錄中的ckfinder.dll控件

2. 拖放控件到Web頁面

3. 修改CKFinder控件屬性BasePath為ckfinder目錄的相對路徑

常見問題

1. 症狀:因為安全原因,檔案不可浏覽。請聯系系統管理者并檢查CKFinder配置檔案。

原因:未設定使用者身份驗證或者使用者未登入。

語句:

複制代碼 代碼如下:

public override bool CheckAuthentication()

{

return false;

}

解決:在CKFinder的config.ascx檔案中修改public override bool CheckAuthentication() 加入使用者身份權限驗證方法。

2. 症狀:未知錯誤

原因:設定不進行使用者身份驗證,但是 BaseUrl 路徑不對。

語句:

複制代碼 代碼如下:

public override bool CheckAuthentication()

{

return true ;

}