Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > FileExplorer > Renaming File, disallow extensions, cancel move?

Not answered Renaming File, disallow extensions, cancel move?

Feed from this thread
  • Michael avatar

    Posted on Jan 9, 2012 (permalink)

    Hi,
    I have a FileExplorer which allows certain types of Image files.  What we would like to achieve is to disallow the user renaming the file extension. We are happy to let them rename the file just not the extension.  I have created the below code based on information I found from your help documents.  Unfortunately, although this does work and does cancel the action, it gets rid of the file rename dialogue box. Which means that after a rename, we can tell the user they cannot change the extension but then the window is closed and they have to click rename again.   So, my questions are:

    A. Is there a way to tell the FileExplorer to disallow extension renaming? (simply don't give them the extension in the textbox maybe)
    B. Is there another event which fire before the box closes to I can check the extensions and cancel the rename before the box closes?
    C. Is there a way to keep the rename dialogue open from the below code?

    Thanks,
    Michael 

    Protected Sub docExplorer_ItemCommand(ByVal sender As Object, ByVal e As RadFileExplorerEventArgs) Handles docExplorer.ItemCommand
        Select Case e.Command
            Case "MoveFile"
                Dim oldExt As String = System.IO.Path.GetExtension(e.Path)
                Dim newExt As String = System.IO.Path.GetExtension(e.NewPath)
                If Not oldExt = newExt Then
                    e.Cancel = True
                End If
                Exit Select
     
        End Select

    Reply

  • Dobromir Dobromir admin's avatar

    Posted on Jan 12, 2012 (permalink)

    Hi Michael,

    In short, no, it is not possible to configure RadFileExplorer to "hide" the extensions of the files in the Rename dialog, nor its possible to keep the dialog open. The closest solution to this case that I offer, is to handle the ClientMove client-side event and cancel it if the file extension is changed, e.g.:
    function explorerMove(explorer, args)
    {
        //check if the event is fired by Rename command
        if (args.get_newPath().search("/") < 0) {
            if (!args.get_item().isDirectory()) { //check if the renamed item is file or folder
     
                var orgExt = args.get_path().substring(args.get_path().lastIndexOf("."));
                var newExt = args.get_newPath().substring(args.get_newPath().lastIndexOf("."));
     
                if (orgExt != newExt) {
                    alert("Changing the file extension is not allowed");
                    args.set_cancel(true); //cancel further execution of the command
                }
            }
        }
    }

    Handling the client-side event will prevent the unnecessary postback to the server, however, the user will have to call the Rename dialog again.

    Regards,
    Dobromir
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now

    Reply

  • Michael avatar

    Posted on Jan 16, 2012 (permalink)

    Hi Dobromir  
    ,
    Thanks for your response. We have decided to go about it slightly differently in that now if the user changes the file extension we add the file extension back on. So if File.txt get renamed to File.doc we would force the extension on so the file would become File.doc.txt.  Not ideal but does the job.

    If it could be submitted as a feature request that would be brilliant. I can imagine there are many people not wanting to allow there users to rename files and although the current solution works it isn't ideal from a user 
    point of view.

    Many Thanks,
    Michael

    Reply

  • Dobromir Dobromir admin's avatar

    Posted on Jan 16, 2012 (permalink)

    Hi Michael,

    I have added your Feature Request to our PITS System, where you can vote for it and follow its status.
    You can find the PITS Item following this link.

    Greetings,
    Dobromir
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > FileExplorer > Renaming File, disallow extensions, cancel move?
Related resources for "Renaming File, disallow extensions, cancel move?"

ASP.NET FileExplorer Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]