<html xmlns="<head runat="server">
<title>無標(biāo)題頁</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server">
</FCKeditorV2:FCKeditor>
</div>
</form>
</body>
</html>
如何獲取其內(nèi)容呢?讀取FCKeditor1控件的Value屬性值即可。
到這里基本OK了,但是我發(fā)現(xiàn)在使用圖片上傳功能的時(shí)候,會(huì)彈出一個(gè)阻止框,顯示"this connector is disabled Please check the"editor/filemanager/connectors/aspx/config.aspx",解決這個(gè)錯(cuò)誤的方法是打開editor/filemanager/connectors/aspx/config.ascx修改CheckAuthentication()方法,返回true
C# code
private 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 in your system.
return true;
}
下載地址:http://www.fckeditor.net/download
FCKeditor使用
一、配置
1、在www.fckeditor.net點(diǎn)擊Download,下載FCKEditor_2.5.1.zip和FCKEditor.Net(ASP.NET Control to easily integrate FCKEditor on .Net Web pages.)
2、新建一項(xiàng)目,比如叫FCK。解壓FCKEditor_2.5.1.zip,里面有個(gè)fckeditor目錄。把該目錄整個(gè)復(fù)制到新建的ASP.NET項(xiàng)目根目錄下。打開fckeditor目錄下的fckconfig.js,修改二項(xiàng):
FCKConfig.DefaultLanguage = 'en' ;
改為
FCKConfig.DefaultLanguage = 'zh-cn' ;
-----------------------------------------------------
var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php | py
改為
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
3、在vs05/08的工具箱上新建一個(gè)名叫FCKEditor的Tab,然后在里面點(diǎn)右鍵,選擇Choose Item,定位到解壓FCKEditor.Net后生成的FCKEditor2.51\FCKeditor.Net_2.5\bin\Release\2.0目錄下的FredCK.FCKEditorV2.dll。該Tab下就會(huì)生成一個(gè)FCKEditor的.net組件。在vs的Design模式下把該組件拖放到界面上。點(diǎn)擊該組件,在屬性面板上設(shè)置BashPath為/FCK/fckeditor/,注意這里的FCK就是你建的ASP.NET的項(xiàng)目名稱,fckeditor為項(xiàng)目根目錄下的目錄名稱。(注意:/FCK/fckeditor/前后的斜杠,少了一個(gè)都不會(huì)顯示編輯器的)。Ctrl+F5!
其它次要配置(不影響使用):
* 可以把fckeditor目錄及其子目錄下所有下劃下開頭的范例、源文件刪掉。
* 可以在fckeditor目錄下只保留fckconfig.js、fckeditor.js和幾個(gè)xml文件,其余全部刪掉。
* fckeditor目錄下的editor目錄下有個(gè)filemanager目錄,把該目錄下的borswer\default\connectors目錄中除aspx目錄以外的全部目錄刪掉。
* 可以把editor\lang目錄下除zh-cn.js、en.js、zh.js之外的全部刪掉。
二、圖片上傳
FCKEditor支持圖片上傳??梢栽贏SP.NET項(xiàng)目根目錄下添加一目錄,起名為UploadFiles.
在web.config里的appSettings段里
<appSettings>
<add key="FCKEditor:BasePath" value="/FCK/fckeditor"/>
<add key="FCKeditor:UserFilesPath" value="/FCK/UploadFiles/" />
</appSettings>
注意UserFielsPath,這里設(shè)置的/FCK/UploadFiles/指定了要上傳的目錄。個(gè)人認(rèn)為這里的FCK可以認(rèn)為是服務(wù)器上的虛擬目錄名。(另外發(fā)現(xiàn)如設(shè)為時(shí)不起作用)。
當(dāng)上傳圖片時(shí)有可能遇到"this connector is disabled Please check the"editor/filemanager/connectors/aspx/config.aspx"的錯(cuò)誤,這時(shí)可以更改fckeditor\editor\filemanager\connectors\aspx\config.ascx的CheckAuthentication()方法,返回true.
三、簡單的FCKEditor存取數(shù)據(jù)庫及顯示
1、在項(xiàng)目里添加新項(xiàng)Sql Server Database, 文件名保留為Database.mdf。在里面新建一表MyTable,只有兩個(gè)字段,一個(gè)int型自動(dòng)增加的primary key, 另一個(gè)是text類型的MyContent. 我們要把FCKEditor1.Value值存到這個(gè)字段里。
2、先做個(gè)顯示的頁面。項(xiàng)目增加一個(gè)Show.aspx,拖一個(gè)SqlDataSource,設(shè)置一下返回MyTable的內(nèi)容。再用Repeater顯示。
//代碼
<asp:Repeater ID="myRepeater" runat="server" DataSourceID="SqlDataSource1">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Eval("MyContent") %>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%nbsp;ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [OID], [MyContent] FROM [MyTable] ORDER BY [OID] DESC"></asp:SqlDataSource>
3、存入數(shù)據(jù)庫
項(xiàng)目中引用System.Configuration(為了使用System.Web.WebConfigurationManager)
在FCKEditor界面上入一個(gè)按鈕,然后
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "insert into MyTable(MyContent) values(@FCKContent)";
cmd.Parameters.AddWithValue("FCKContent",FCKeditor1.Value);
conn.Open();
cmd.ExecuteNonQuery();
}
}