那麼爲什麼說是FCKeditor的冰冷之心呢?這不是譁衆取寵,主要是說它使用起來有點麻煩,下文就詳細說明如何搞定這玩意兒。
1.FCKeditor的官方網站是:http://www.fckeditor.net/download
目前最新的FCKeditor 2.4.2版本。
請在此頁下載:http://sourceforge.net/project/showfiles.php?group_id=75348
如圖所示:
要下載FCKeditor2.4.2.zip和 FCKeditor.NET版的2個zip包。
說明:
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。其他文件沒用,把FredCK.FCKeditorV2.dll複製到我們的網站,建立一個Bin目錄。
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,因爲FCKeditor使用這個值來返回你上傳後的文件的相對路徑到客戶端。否則的話客戶訪問的時候就會取客戶的機器目錄而不是http形式的目錄。
建議: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" %>
<!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>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>