1. 用 Visual Studio 2005/2008 打开项目 FCKeditor.Net 2.6.3(下载:),打开文件“FileBrowser/Connector.cs”,在成员函数GetFiles下方 增加如下两个成员函数:
/// <summary>
/// 删除文件
/// </summary>
/// <param name="connectorNode"></param>
/// <param name="resourceType"></param>
/// <param name="currentFolder"></param>
private void DelFile(XmlNode connectorNode, string resourceType, string currentFolder)
{
System.Web.HttpContext hc = System.Web.HttpContext.Current;
string file = hc.Server.MapPath(hc.Request["FileUrl"]);
if (System.IO.File.Exists(file))
{
System.IO.File.Delete(file);
}
else
{
hc.Response.Write(@"<error number=""1"" originaldescription=""unable to locate file"">");
}
}
/// <summary>
/// 删除目录
/// </summary>
/// <param name="connectorNode"></param>
/// <param name="resourceType"></param>
/// <param name="currentFolder"></param>
private void DelFolder(XmlNode connectorNode, string resourceType, string currentFolder)
{
System.Web.HttpContext hc = System.Web.HttpContext.Current;
string folder = hc.Server.MapPath(hc.Request["FolderName"]);
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 部分增加以下蓝色代码:
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 拷贝出来放在项目的bin目录。
4. 打开“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=\'#\'" /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;" onmouseover="showimgdiv(\''+ProtectPath( fileUrl ) + '\');" onmouseout="hiddendiv()">' ;
- // Get the file icon.
- var sIcon = oIcons.GetIcon( fileName ) ;
- return '<tr>' +
- '<td width="16">' +
- sLink +
- '<img alt="" src=\'#\'" /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>' ;
- }
5. 继续修改文件“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);
}
}
function showimgdiv(str)
{
document.getElementById("imgdiv").style.display="block";
document.getElementById("imgsrc").src=str;
}
function hiddendiv()
{
document.getElementById("imgdiv").style.display="none";
}
6. 继续修改文件“frmresourceslist.htm”,找到 GetFoldersAndFilesCallBack 函数中的下面这行,增加蓝色部分的代码
oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/", sCurrentFolderUrl ) );
到此为止,删除文件和删除文件夹的功能已实现, 要实现鼠标移到文件名上面在右边出现图片预览的效果,还要修改一个地方:
找到 GetFoldersAndFilesCallBack 函数中的下面这行,增加蓝色部分的代码:
oHtml.Append("<div id=\"imgdiv\" style=\"position:absolute;overflow:scroll;right:0px; top:0px; width:300px; height:300px; border:1px solid #000000;display:none\" ><img id=\"imgsrc\" /></div>");