为 FCKeditor增加图片预览和删除文件、删除文件夹功能(c#)

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”,修改以下两个函数
 

  
  
  
  
  1. oListManager.GetFolderRowHtml = function( folderName, folderPath,folderUrl)  
  2. {  
  3.     // Build the link to view the folder.  
  4.     var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;">' ;  
  5.  
  6.     return '<tr>' +  
  7.             '<td width="16">' +  
  8.                 sLink +  
  9.                 '<img alt="" src=\'#\'" /Folder.gif" width="16" height="16" border="0"><\/a>' +  
  10.             '<\/td><td nowrap colspan="2">&nbsp;' +  
  11.                 sLink +  
  12.                 folderName +  
  13.                 '<\/a>' +  
  14.         '<\/td><td align="right"><a href="#" onclick="DelFolder(\''+folderName+'\',\''+ ProtectPath(folderUrl) + '\');return false;">删除</a></td><\/tr>' ;  
  15. }  
  16.  
  17. oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize )  
  18. {  
  19.     // Build the link to view the folder.  
  20.     var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;" onmouseover="showimgdiv(\''+ProtectPath( fileUrl ) + '\');" onmouseout="hiddendiv()">' ;  
  21.  
  22.     // Get the file icon.  
  23.     var sIcon = oIcons.GetIcon( fileName ) ;  
  24.  
  25.     return '<tr>' +  
  26.             '<td width="16">' +  
  27.                 sLink +  
  28.                 '<img alt="" src=\'#\'" /icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +  
  29.             '<\/td><td>&nbsp;' +  
  30.                 sLink +  
  31.                 fileName +  
  32.                 '<\/a>' +  
  33.             '<\/td><td align="right" nowrap>&nbsp;' +  
  34.                 fileSize +  
  35.                 ' KB' +  
  36.         '<\/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>");

你可能感兴趣的:(fckeditor,删除文件,休闲,删除文件夹,预览)