方法一:不修改源码
1、在\fckeditor\editor\filemanager\browser\default文件夹中找到frmresourceslist.html文件,将
oListManager.GetFileRowHtml和oListManager.GetFolderRowHtml代码修改如下:
//
在文件夹后放置“删除”
oListManager.GetFolderRowHtml
=
function
(folderName, folderPath, folderUrl) {
//
Build the link to view the folder.
var
sLink
=
'
<a href="#" onclick="OpenFolder(\
''
+ ProtectPath(folderPath) +
'
\
'
);return false;">
'
;
return
'
<tr>
'
+
'
<td width="16">
'
+
sLink
+
'
<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>
'
+
'
<\/td><td nowrap colspan="2">
'
+
sLink
+
folderName
+
'
<\/a>
'
+
'
<\/td>
<td align="right"><a href="#" onclick="DeleteFolder(\
'' +
folderName + '\',\'' +
ProtectPath(folderUrl) +
'\'
);return false;">删除</a></td>
<\/tr>
'
;
}
//
在文件后放置“删除”
oListManager.GetFileRowHtml
=
function
(fileName, fileUrl, fileSize) {
var
sLink
=
'
<a href="#" onclick="OpenFile(\
''
+ ProtectPath(fileUrl) +
'
\
'
); return false;">
'
;
var
sIcon
=
oIcons.GetIcon(fileName);
return
'
<tr>
'
+
'
<td width="16">
'
+
sLink
+
'
<img alt="" src="images/icons/
'
+
sIcon
+
'
.gif" width="16" height="16" border="0"> <\/a>
'
+
'
<\/td><td>
'
+
sLink
+
fileName
+
'
<\/a>
<a href="#" onclick="deleteFile(\
'' +
fileName + '\',\'' + ProtectPath(fileUrl)
+ '\');" style="color: #FF9933;"> 删除 <\/a>' +
'
<\/td><td align="right" nowrap>
'
+
fileSize
+
'
KB
'
+
'
<\/td><\/tr>
'
;
}
2、在该文件的js中增加如下代码:
//
产生不重复的随机数
var
rn
=
Math.ceil(Math.random()
*
1000000
);
var
rnch
=
rn;
function
rndnum() {
while
(rn
==
rnch) rn
=
Math.ceil(Math.random()
*
1000000
);
rnch
=
rn;
return
rn;
}
//
删除文件
function
deleteFile(fileName, file) {
var
xml
=
new
ActiveXObject(
"
MSXML2.XMLHTTP
"
);
if
(confirm(
'
您确定要删除“
'
+
fileName
+
'
”吗?
'
)) {
xml.open(
"
get
"
,
"
FCKdel_file.aspx?filePath=
"
+
file
+
"
&UD=
"
+
rndnum(),
false
);
xml.send();
Refresh();
switch
(xml.responseText.substring(
0
,
1
)) {
case
"
1
"
: alert(
"
文件删除成功!
"
);
break
;
case
"
0
"
: alert(
"
文件删除失败!请检查文件是否存在!
"
);
break
;
case
"
2
"
: alert(
"
您不是系统管理员,无权进行操作!
"
);
break
;
default
: alert(
"
未知错误!
"
);
break
;
}
}
}
//
删除文件夹
function
DeleteFolder(folderName, folderPath) {
var
xml
=
new
ActiveXObject(
"
MSXML2.XMLHTTP
"
);
if
(confirm(
'
您确定要删除文件夹“
'
+
folderName
+
'
”和里面的所有文件吗?
'
)) {
xml.open(
"
get
"
,
"
FCKDel_folder.aspx?folderPath=
"
+
escape(folderPath
+
folderName)
+
"
&UD=
"
+
rndnum(),
false
);
xml.send();
Refresh();
switch
(xml.responseText.substring(
0
,
1
)) {
case
"
1
"
: alert(
"
文件夹删除成功!
"
);
break
;
case
"
0
"
: alert(
"
文件夹删除失败!请检查文件是否存在!
"
);
break
;
case
"
2
"
: alert(
"
您不是系统管理员,无权进行操作!
"
);
break
;
default
: alert(
"
未知错误!
"
);
break
;
}
}
}
继续修改文件“frmresourceslist.htm”,找到 GetFoldersAndFilesCallBack 函数中的下面这行,增加红色部分的代码:
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath
+
sFolderName
+
"
/
"
, sCurrentFolderUrl
) );
3、增加文件
在同一个目录(指frmresourceslist.html所在目录)中增加FCKdel_file.aspx,用于删除文件。代码如下:
<%
@ Page Language
=
"
C#
"
%>
<%
if
(Request.QueryString[
"
UD
"
] !
=
null
)
{
try
{
string
file
=
Request.QueryString[
"
filePath
"
].Trim();
string
filePath
=
Server.MapPath(file);
if
(System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
Response.Write(
"
1
"
);
}
else
{
Response.Write(
"
0
"
);
}
}
catch
{
Response.Write(
"
0
"
);
}
}
else
Response.Write(
"
2
"
);
%>
在同一个目录(指frmresourceslist.html所在目录)中增加FCKDel_folder.aspx,用于删除文件夹。代码如下:
<%
@ Page Language
=
"
C#
"
%>
<%
if
(Request.QueryString[
"
UD
"
] !
=
null
)
{
try
{
string
file
=
HttpUtility.UrlDecode(Request.QueryString[
"
folderPath
"
].Trim());
string
filePath
=
Server.MapPath(file);
if
(System.IO.Directory.Exists(filePath))
{
System.IO.Directory.Delete(filePath,
true
);
Response.Write(
"
1
"
);
}
else
{
Response.Write(
"
0
"
);
}
}
catch
{
Response.Write(
"
0
"
);
}
}
else
Response.Write(
"
2
"
);
%>
完成,测试,成功。
方法二:修改源码(本文所针对版本:FCKeditor: 2.6.4,FCKeditor.Net: 2.6.3。)
首先下载FCKeditor控件的源码——FCKeditor.Net。
1. 打开项目 FCKeditor.Net,打开文件“FileBrowser/Connector.cs”,为 class Connector 增加如下两个成员函数:
//
删除文件
private
void
DelFile(XmlNode connectorNode,
string
resourceType,
string
currentFolder)
{
HttpContext hc
=
HttpContext.Current;
string
file
=
hc.Server.MapPath(HttpUtility.UrlDecode(hc.Request[
"
FileUrl
"
], System.Text.Encoding.UTF8));
if
(System.IO.File.Exists(file))
System.IO.File.Delete(file);
else
hc.Response.Write(
@"
<error number=""1"" originaldescription=""unable to locate file"">
"
);
}
//
删除文件夹
private
void
DelFolder(XmlNode connectorNode,
string
resourceType,
string
currentFolder)
{
HttpContext hc
=
HttpContext.Current;
string
folder
=
hc.Server.MapPath(HttpUtility.UrlDecode(hc.Request[
"
FolderName
"
], System.Text.Encoding.UTF8));
if
(System.IO.Directory.Exists(folder))
System.IO.Directory.Delete(folder,
true
);
else
hc.Response.Write(
@"
<error number=""2"" originaldescription=""unable to locate folder"">
"
);
}
2. 在文件“Connector.cs”中找到 OnLoad 函数,在 switch 部分增加以下红色代码:
//
Execute the required command.
switch
(sCommand)
{
case
"
GetFolders
"
:
this
.GetFolders(oConnectorNode, sResourceType, sCurrentFolder);
break
;
case
"
GetFoldersAndFiles
"
:
this
.GetFolders(oConnectorNode, sResourceType, sCurrentFolder);
this
.GetFiles(oConnectorNode, sResourceType, sCurrentFolder);
break
;
case "CreateFolder":
this.CreateFolder(oConnectorNode, sResourceType, sCurrentFolder);
break;
case "DelFile":
this.DelFile(oConnectorNode, sResourceType, sCurrentFolder);
break;
case "DelFolder":
this.DelFolder(oConnectorNode, sResourceType, sCurrentFolder);
break
;
default
:
XmlResponseHandler.SendError(Response,
1
,
"
Command is not allowed
"
);
break
;
}
3. 编译 FCKeditor.net 并关闭该项目。将生成的 FredCK.FCKeditorV2.dll 拷贝出来用于Web项目的引用。
4. 建立 C# 测试项目,并在其中部署 FCKeditor 2.6.4(使用第 3 步生成的 FredCK.FCKeditorV2.dll)。
5. 打开“fckeditor/editor/filemanager/browser/default/frmresourceslist.htm”,修改以下两个函数
oListManager.GetFolderRowHtml
=
function
( folderName, folderPath
, folderUrl
)
{
//
Build the link to view the folder.
var
sLink
=
'
<a href="#" onclick="OpenFolder(\
''
+ ProtectPath(folderPath) +
'
\
'
);return false;">
'
;
return
'
<tr>
'
+
'
<td width="16">
'
+
sLink
+
'
<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>
'
+
'
<\/td><td nowrap colspan="2">
'
+
sLink
+
folderName
+
'
<\/a>
'
+
'
<\/td>
<td align="right"><a href="#" onclick="DelFolder(\
''+folderName+'
\',\''+ ProtectPath(folderUrl) + '\'
);return false;">删除</a></td>
<\/tr>
'
;
}
oListManager.GetFileRowHtml
=
function
( fileName, fileUrl, fileSize )
{
//
Build the link to view the folder.
var
sLink
=
'
<a href="#" onclick="OpenFile(\
''
+ ProtectPath(fileUrl) +
'
\
'
);return false;">
'
;
//
Get the file icon.
var
sIcon
=
oIcons.GetIcon( fileName ) ;
return
'
<tr>
'
+
'
<td width="16">
'
+
sLink
+
'
<img alt="" src="images/icons/
'
+
sIcon
+
'
.gif" width="16" height="16" border="0"><\/a>
'
+
'
<\/td><td>
'
+
sLink
+
fileName
+
'
<\/a>
'
+
'
<\/td><td align="right" nowrap>
'
+
fileSize
+
'
KB
'
+
'
<\/td>
<td align="right"><a href="#" onclick="DelFile(\
''+fileName+'\',\'' +
ProtectPath(fileUrl) + '\'
);return false;">删除</a></td>
<\/tr>
'
;
}
6. 继续修改文件“frmresourceslist.htm”,在 OpenFile 函数后面增加以下两个函数:
function
DelFile( fileName, fileUrl )
{
if
(confirm(
'
您确定要删除文件“
'
+
fileName
+
'
”吗?
'
))
oConnector.SendCommand(
"
DelFile
"
,
"
FileUrl=
"
+
escape(fileUrl), Refresh);
}
function
DelFolder( folderName, folderPath )
{
if
(confirm(
'
您确定要删除文件夹“
'
+
folderName
+
'
”和里面的所有文件吗?
'
))
oConnector.SendCommand(
"
DelFolder
"
,
"
FolderName=
"
+
escape(folderPath
+
folderName), Refresh);
}
7. 继续修改文件“frmresourceslist.htm”,找到 GetFoldersAndFilesCallBack 函数中的下面这行,增加红色部分的代码:
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath
+
sFolderName
+
"
/
"
, sCurrentFolderUrl
) );
至此,删除功能增加完毕。
参考文章:http://www.cnblogs.com/mxh691/archive/2009/06/24/1510032.html
http://hi.baidu.com/yangw80/blog/item/0292e0f00d345ea6a40f52a5.html