Home DotNet How to delete uploaded file from FCKEditor
Author:

We have a really cool CMS built in-house which uses the FCKeditor component. On one morning the user have ask if she could delete obsolete files that she has upload ages ago.  I thought to myself hmm that is a good question, so I hit to the computer and fire up Internet Explorer, then I open up the CMS page and observe if I could delete the uploaded file from the file manager. To my surprise the delete function is not there, but I knew it must be for the security reason why the author did not wanted to have the delete function there.

So if you really want to have the delete function and you know that it wont pose a great risk to your server, how would go about implementing the function?

Well, thank god it’s not that to difficult. You will most likely need to modify just five files to have the delete function working.

  1. frmresourcelist.html - \FCKEditor\editor\filemanager\browser\default\frmresourcelist.html
  2. commands.asp - \FCKEditor\editor\filemanager\browser\default\connector\asp\commands.asp
  3. connector.asp - \FCKEditor\editor\filemanager\browser\default\connector\asp\connector.asp
  4. config.asp - \FCKEditor\editor\filemanager\browser\default\connector\asp\config.asp
  5. fckconfig.js - \FCKEditor\fckconfig.js

Change of what is hightlighted in yellow


1. Change frmresourcelist.html - \FCKEditor\editor\filemanager\browser\default\frmresourcelist.html

oListManager.AddFile = function(fileName, fileUrl, fileSize) {

        // Create the new row.

        var oRow = this.Table.insertRow(-1); 

        // Build the link to view the folder.
        var sLink = '<a href="#" onclick="OpenFile(\'' + fileUrl + '\');return false;">';
        var sLinkDelete = '<a href="#" onclick="DeleteFile(\'' + fileUrl + '\');return false;">'; 

        // Get the file icon.
        var sIcon = oIcons.GetIcon(fileName); 

        // Add the file icon cell.
        var oCell = oRow.insertCell(-1);
        oCell.width = 16;
        oCell.innerHTML = sLink + '<img alt="" src="/images/icons/' + sIcon + '.gif" width="16" height="16" border="0"></a>'

        // Add the file name cell.
        oCell = oRow.insertCell(-1);
        oCell.innerHTML = '&nbsp;' + sLink + fileName + '</a>';

        // Add the file size cell.
        oCell = oRow.insertCell(-1);
        oCell.noWrap = true;
        oCell.align = 'right';
        oCell.innerHTML = '&nbsp;' + fileSize + ' KB' + sLinkDelete + ' delete</a>';
    }

Then add this sub-routine near the end of the file 

function DeleteFile(fileUrl) {
        if (confirm("Delete this file ?") == true) {
            oConnector.SendCommand('RemoveFile', 'DeleteFileName=' + encodeURI(fileUrl).replace('#', '%23'), DeleteFileCallBack);
        }
    }

    function DeleteFileCallBack(fckXml) {
        window.parent.frames['frmResourcesList'].Refresh();
    }

  
2.  commands.asp - \FCKEditor\editor\filemanager\browser\default\connector\asp\commands.asp

Open up the commands.asp file and add the follow changes: This sub-routine will be called from the client to actually deletes the files on the server.  

Sub RemoveFile(ByVal resourceType, ByVal currentFolder)
    Dim sDeleteFileName
    Dim fso
    sDeleteFileName = Request.QueryString("DeleteFileName")
    sDeleteFileName = Server.MapPath(sDeleteFileName)
    fso = Server.CreateObject("Scripting.FileSystemObject")
 

    If fso.FileExists(sDeleteFileName) = True Then
        fso.DeleteFile(sDeleteFileName, True)
    End If 

    fso = Nothing
End Sub
 

3.  connector.asp - \FCKEditor\editor\filemanager\browser\default\connector\asp\connector.asp

Open up the connector.asp file and change the line highlighted in yellow. 

' Execute the required command.

    Select Case sCommand
        Case "GetFolders"
            GetFolders sResourceType, sCurrentFolder
        Case "GetFoldersAndFiles"
            GetFoldersAndFiles sResourceType, sCurrentFolder
        Case "CreateFolder"
            CreateFolder sResourceType, sCurrentFolder
        Case "RemoveFile"
            RemoveFile sResourceType, sCurrentFolder           
    End Select



4. config.asp - FCKEditor\editor\filemanager\browser\default\connector\asp\config.asp
  

If you are using the asp.net connector then you have to change it to use the asp connector as currently I have not come up with a solution to use the asp.net connector.
 
Ensure that the configIsEnable = true.
  
Dim ConfigIsEnabled
ConfigIsEnabled = true
  
5. fckconfig.js

Then make sure that you have change the ConfigUserFilesPath to the correct path. This is the upload path of files.

Dim ConfigUserFilesPath
ConfigUserFilesPath = "/retirementpolicybenefit/UserFiles
/"

Open up the file fckconfig.js and modify the following line. Make sure that the connector.asp is uncommented and comment out the connect.aspx because we are not using the asp.net connector.
 
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Connector=connectors/asp/connector.asp' ;

//FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Connector=connectors/asp/connector.asp&ServerPath=/CustomFiles/' ;
//FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Connector=connectors/aspx/connector.aspx' ;
  

There you have it you can test it out and see if you now can delete file in FCKeditor.



Comments (11)
  • raby  - what version ?
    What is your version of fckeditor?
    in my version 2.30, file frmresourcelist.html does not contain these lines.
  • raby  - sorry
    it's an asp version
    mine is php

    sorry
  • qv
    yeah this is only for asp.
  • Old?ich Válek  - PHP
    Version for php? I found one here: http://tgrove.com/2008/02/17/fckeditor-file-manager-delete-files-and-f olders/

    But if i done everything what they saying i dont get any files or folders in fck filemanager :0
  • Nabil Makarem  - XML error
    Hi,


    I followed the steps from 1 to 5. However, I received an error "XML Request error: Internal server error (500)" and then no files appear. When I use my old files, I can see all the files. So my problem is that when I use the steps you told me about, I receive an error. The website is currently on my local PC.

    Nabil M.
  • Anonymous
    my app was java? so i can't find **.asp file
  • Anonymous
    fso requires a set in front of it

    Sub RemoveFile(ByVal resourceType, ByVal currentFolder)
    Dim sDeleteFileName
    Dim fso
    sDeleteFileName = Request.QueryString("DeleteFileName")
    sDeleteFileName = Server.MapPath(sDeleteFileName)
    set fso = Server.CreateObject("Scripting.FileSystemObject")


    If fso.FileExists(sDeleteFileName) = True Then
    fso.DeleteFile(sDeleteFileName, True)
    End If

    set fso = Nothing
    End Sub
  • Mezz  - ASPX version another way
    This way for aspx version by $.ajax call

    at the function DeleteFile(fileUrl) of step 1 changingcode inside like this :


    var succeededAjaxFn = function (result) {
    if (result.d != "") {
    alert(result.d);
    }
    else {//delete completed
    Refresh();
    }
    }
    var failedAjaxFn = function (result) {
    alert('error: ' + result.d);
    }

    $.ajax({
    type: "POST",
    url: "../../connectors/aspx/delete.aspx/DeleteUploadFile",
    contentType: "application/json; charset=utf-8",
    data: '{"filename":"' + fileUrl + '"}',
    dataType: "json",
    success: succeededAjaxFn,
    error: failedAjaxFn
    ...
  • Mezz  - re: ASPX version another way
    This way for aspx version by $.ajax call
    at the function DeleteFile(fileUrl) of step 1 changingcode inside like this :
    at the function DeleteFile(fileUrl) of step 1 changing code inside like this :


    var succeededAjaxFn = function (result) {
    if (result.d != "") {
    alert(result.d);
    }
    else {//delete completed
    Refresh();
    }
    }
    var failedAjaxFn = function (result) {
    alert('error: ' + result.d);
    }

    $.ajax({
    type: "POST",
    url: "../../connectors/aspx/delete.aspx/DeleteUploadFile",
    contentType: "application/json; charset=utf-8",
    data: '{"filename":"' + fileUrl + '"}',
    dataType: "json",
    success...
  • Mezz
    and aspx code behind
    dot'n forget to import:
    Imports System.IO
    Imports System.Web.Services


    _
    Public Shared Function DeleteUploadFile(ByVal filename As String) As String
    Dim returnValue As String
    returnValue = ""

    Try
    Dim fileFullPath As String

    fileFullPath = HttpUtility.UrlDecode(filename, Encoding.GetEncoding("utf-8"))
    fileFullPath = HttpContext.Current.Server.MapPath(fileFullPath)

    If File.Exists(fileFullPath) Then File.Delete(fileFullPath)
    If File.Exists(fileFullPath) Then
    returnValue = "???????????????????????? ??????????????????????: ??????????????? " & fileFullPath
    End If
    Catch ex As Exception
    WebLog.doLog(ex)
    returnValue = "???????????????????????? ??????????????????????: " & ex.Message()
    End Try

    Return returnValue
    End Function
Write comment
Your Contact Details:
Comment:
Security
Please input the anti-spam code that you can read in the image.

"