ASP.NET2.0 文字編輯器FCKeditor的冰冷之心
FCKeditor是目前最好的html文字編輯器,如果還不明白的話看了下圖就知道了
效果圖:
那麼為什麼說是FCKeditor的冰冷之心呢?這不是譁眾取寵,主要是說它使用起來有點麻煩,下文就詳細說明如何搞定這玩意兒。
說明:
FCKeditor2.4.2.zip是其最新的Javascript檔案和圖片什麼的;
FCKeditor.NET.zip是ASP.NET呼叫的DLL在裡面。
2.分別解壓後把FCKeditor2.4.2.zip裡的fckeditor目錄整個複製到網站中。
3.解壓FCKeditor.NET.zip包後在FCKeditor.Net_2.2/bin/Debug目錄裡找到FredCK.FCKeditorV2.dll
4.引用FredCK.FCKeditorV2.dll。
第一步:
第二步:
5.匯入工具箱。
在“工具箱”下右鍵
點選“選擇項”。彈出如圖視窗:
點選瀏覽,找到dll所在目錄。
這時發現工具箱裡多出FCKeditor控制元件。
6.拖拽FCKeditor到頁面上
7.配置WebConfig
<?xml version="1.0"?>
<!--
注意: 除了手動編輯此檔案以外,您還可以使用
Web 管理工具來配置應用程式的設定。可以使用 Visual Studio 中的
“網站”->“Asp.Net 配置”選項。
設定和註釋的完整列表在
machine.config.comments 中,該檔案通常位於
/Windows/Microsoft.Net/Framework/v2.x/Config 中
-->
<configuration>
<appSettings>
<add key="FCKeditor:BasePath" value="~/fckeditor/"/>
<add key="FCKeditor:UserFilesPath" value="/Files/" />
</appSettings>
<connectionStrings/>
<system.web>
說明:BasePath是fckeditor所在路徑,fckeditor由於我們直接放網站目錄下這樣寫就可以,如果您的網站多放幾層適當調整即可。
UserFilesPath是所有上傳的檔案的所在目錄。為什麼要設定成/Files
建議:Files要單獨做wwwroot目錄下的一個站點比較好,和我們的站點FCKEditor平行。不要把它放FCKEditor裡,為什麼呢?因為Files是要讓客戶有寫的許可權的,如果放FCKEditor下很危險。
8.Files目錄要有寫的許可權。你根據自己網站需求設定那個帳號,本文為方便設定User實際中你可能用ASP.NET帳號更合理。
9.修改fckeditor/fckconfig.js檔案
在第182行的位置
var _FileBrowserLanguage = 'asp' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'asp' ; // asp | aspx | cfm | lasso | php
改為
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | php
10.FCKeditor給其瘦身。以_打頭的的都是範例檔案或原始檔,不過建議小心。
11.下面以上傳圖片示例說明如何使用,
點選“瀏覽伺服器”。
彈出視窗很容易報錯
如果報錯XML request error: Internal Server Error(500),很可能就是目錄路徑不對和寫許可權沒有。
選擇影象
最後效果
前臺程式碼:
<%@ Page Language="C#" validateRequest=false AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FCKeditor文字編輯器</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<fckeditorv2:fckeditor id="FCKeditor1" runat="server" DefaultLanguage="zh-cn" Height="400px" Width="660px"
></fckeditorv2:fckeditor>
</div>
</form>
</body>
</html>
怎麼樣獲取結果呢?FCKeditor1.Value就是。
12.還有個類似的控制元件FreeTextBox也很好用,有興趣可以自己網上找找,比這個好用多了不過感覺沒這個好,而且它的最新版似乎收費了。