explain source: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Integration/ASP.NET
code source FCKeditor2.6.4: http://sourceforge.net/project/downloading.php?group_id=75348&filename=FCKeditor_2.6.4.zip
code source FCKeditor2.6.3 net: http://www.fckeditor.net/download
1. 下载
FCKeditor_2.6.3.zip(核心文件)
FCKeditor.Net_2.6.3.zip(。Net Control)
2. 部署到.NET网站中
//FCKeditor_2.6.3.zip解压后将fck根目录改名为FckTools,放到网站根目录下。(经操作无必要)
网站根目录下创建一个文件夹FckFiles,用于存放上传的文件
在网站中引用FCKeditor.Net_2.6.3.zip中的“FredCK.FCKeditorV2.dll”将个文件复制到网站bin目录中
在.NET中工具箱中,在常规面板中右键选择[选择项],在打开的 "选择工具箱项"选 择[.NET Framework组件],单击[浏览]找到站点下的FredCK.FCKeditorV2.dll文件。正确添加后,可以在工具箱中看到FCKeditor控件。
3. 简化fck配置
删除所有以_开始的文件和文件夹,在filemanager中的connector中除aspx以外的文件夹
4. 修改fck的语言
fckeditor中的fckconfig.js
61~63行
FCKConfig.AutoDetectLanguage = false ;
FCKConfig.DefaultLanguage = 'zh-cn' ;
FCKConfig.ContentLangDirection = 'ltr' ;
5. 修改上传和浏览文件的程序语言类型
fckeditor中的fckconfig.js
276~277行
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
web.config->
<appSettings>
<add key="FCKeditor:BasePath" value="/FckTools/"/>
<add key="FCKeditor:UserFilesPath" value="/FckFiles/" />
</appSettings>
default.aspx->
<%@ Page Language="C#"%>
<%@ 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>Sample Page</title>
</head>
<body>
<form id="form1" runat="server">
<FCKeditorV2:FCKeditor ID="FCKeditor1" runat="server">
</FCKeditorV2:FCKeditor>
<div>
</div>
<input type="submit" value="Submit" runat="server" />
</form>
</body>
</html>
default.aspx.cs->
empty
upload set->
fckeditor2.6.3默认已经在fckconfig.js中允许被授权的连接上传和浏览文件了,但是默认情况下有将所有的连接都设为了未授权状态。修改方法为修改editor/filemanager/connector/aspx/config.ascx
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;
}
找到CheckAuthentication方法,默认情况返回false,这里要改为true。也可以根据登录情况来选择权限检测的返回值。
至此,上传设置已经完成!
下面讲一下上传设置的优化:
1. fckeditor的上传有两种方式:quick方式和非quick方式。
非quick方式是通过单击“浏览服务器”,在“浏览服务器”窗口中上传。这种上传根据上传文件的类型,自动上传到相应的目录,例如图片自动上传到uploadfiles/image下(uploadfiles为用户自己指定);
quick方式则通过在“上传”选项卡中上传。这种上传直接将文件上传到上传根目录uploadfiles。(uploadfiles为用户自己指定)。
但是个人认为quick上传不好的地方在于所有上传的文件不分类型都放在根目录,很凌乱。所以考虑将这两种上传方式都按照类型存放到相应的文件夹中。
修改方法:
方法1:修改filemanager/connectors/aspx/config.ascx
TypeConfig["File"].AllowedExtensions = new string[] { "7z", "aiff", "asf", "avi", "bmp", "csv", "doc", "fla", "flv", "gif", "gz", "gzip", "jpeg", "jpg", "mid", "mov", "mp3", "mp4", "mpc", "mpeg", "mpg", "ods", "odt", "pdf", "png", "ppt", "pxd", "qt", "ram", "rar", "rm", "rmi", "rmvb", "rtf", "sdc", "sitd", "swf", "sxc", "sxw", "tar", "tgz", "tif", "tiff", "txt", "vsd", "wav", "wma", "wmv", "xls", "xml", "zip" };
TypeConfig["File"].DeniedExtensions = new string[] { };
TypeConfig["File"].FilesPath = "%UserFilesPath%file/";
TypeConfig["File"].FilesAbsolutePath = (UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%file/");
TypeConfig["File"].QuickUploadPath = "%UserFilesPath%file/";
TypeConfig["File"].QuickUploadAbsolutePath = (UserFilesAbsolutePath == "" ? "" : "%UserFilesAbsolutePath%");
将TypeConfig["File"].QuickUploadPath 的值改为与 TypeConfig["File"].FilesPath相同 = "%UserFilesPath%file/";
方法2:修改FCKeditor.Net_2.6.3源代码(较麻烦)
(1). 将FCKeditor.Net_2.6.3.zip解压缩,打开解压后的工程,修改FileBrowser/FileWorkerBase.cs
protected string ServerMapFolder( string resourceType, string folderPath, bool isQuickUpload )
{
TypeConfig typeConfig = this.Config.TypeConfig[ resourceType ];
// Get the resource type directory.
/*-----------修改前-------------------*/
//string sResourceTypePath = isQuickUpload ? typeConfig.GetQuickUploadDirectory() : typeConfig.GetFilesDirectory();
/*------------------------------------*/
/*-----------修改后-------------------*/
string sResourceTypePath = typeConfig.GetFilesDirectory();
/*------------------------------------*/
// Ensure that the directory exists.
Util.CreateDirectory( sResourceTypePath );
// Return the resource type directory combined with the required path.
return System.IO.Path.Combine( sResourceTypePath, folderPath.TrimStart( '/' ) );
}
如上面代码,无论isQuickUpload为true或false,都按照非Quick上传方式,取得上传路径(即typeConfig.GetFilesDirectory())。
(2). 修改fckconfig.js
FCKConfig.LinkBrowser = true ;
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Connector=' + encodeURIComponent( FCKConfig.BasePath + 'filemanager/connectors/' + _FileBrowserLanguage + '/connector.' + _FileBrowserExtension ) ;
FCKConfig.LinkBrowserWindowWidth = FCKConfig.ScreenWidth * 0.7 ; // 70%
FCKConfig.LinkBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ; // 70%
FCKConfig.ImageBrowser = true ;
FCKConfig.ImageBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Image&Connector=' + encodeURIComponent( FCKConfig.BasePath + 'filemanager/connectors/' + _FileBrowserLanguage + '/connector.' + _FileBrowserExtension ) ;
FCKConfig.ImageBrowserWindowWidth = FCKConfig.ScreenWidth * 0.7 ; // 70% ;
FCKConfig.ImageBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ; // 70% ;
FCKConfig.FlashBrowser = true ;
FCKConfig.FlashBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Type=Flash&Connector=' + encodeURIComponent( FCKConfig.BasePath + 'filemanager/connectors/' + _FileBrowserLanguage + '/connector.' + _FileBrowserExtension ) ;
FCKConfig.FlashBrowserWindowWidth = FCKConfig.ScreenWidth * 0.7 ; //70% ;
FCKConfig.FlashBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ; //70% ;
FCKConfig.LinkUpload = true ;
FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=File';
//FCKConfig.LinkUploadAllowedExtensions = "" ; // empty for all
FCKConfig.LinkUploadAllowedExtensions = ".(7z|aiff|asf|avi|bmp|csv|doc|fla|flv|gif|gz|gzip|jpeg|jpg|mid|mov|mp3|mp4|mpc|mpeg|mpg|ods|odt|pdf|png|ppt|pxd|qt|ram|rar|rm|rmi|rmvb|rtf|sdc|sitd|swf|sxc|sxw|tar|tgz|tif|tiff|txt|vsd|wav|wma|wmv|xls|xml|zip)$" ; // empty for all
FCKConfig.LinkUploadDeniedExtensions = "" ; // empty for no one
FCKConfig.ImageUpload = true ;
FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=Image' ;
FCKConfig.ImageUploadAllowedExtensions = ".(jpg|gif|jpeg|png|bmp)$" ; // empty for all
FCKConfig.ImageUploadDeniedExtensions = "" ; // empty for no one
FCKConfig.FlashUpload = true ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=Flash' ;
FCKConfig.FlashUploadAllowedExtensions = ".(swf|flv)$" ; // empty for all
FCKConfig.FlashUploadDeniedExtensions = "" ; // empty for no one
可以看到包括两部分设置:浏览(LinkBrowser、ImageBrowser和FlashBrowser)和上传(LinkUpload、ImageUpload和FlashUpload)。主要是做了如下修改
Code
/*-------修改前------------*/
FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension ;
/*-------修改后-----------*/
FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=File';
在最后加上了Type=File,这样通过添加链接上传的文件就上传到了file目录下。
也可以对FCKConfig.LinkBrowserURL进行修改加上Type=File,这样在点击添加链接里的“浏览服务器”时就只能浏览File目录下的文件和文件夹。可以看到Image和Flash默认时都只能浏览Image和Flash目录,如果去掉Type=Image和Type=Flash就可以浏览上传根目录下的所有目录了。
至此,上传设置就基本完成了。当然还可以对上传做进一步的设置,例如:随机生成文件名;上传目录以year/month/;上传图片加水印等会在以后来贴出来。
-------------------------------------------注意--------------------------------------------------------------------------------
将fck控件拖到页面后一定要看一下控件的一属性:BasePath;
因一般将fck解压缩文件放到项目的根目录下,故BasePath值应改为~/fckeditor/