Rename file by forcing file extension

2 posts, 0 answers
  1. robertw102
    robertw102 avatar
    265 posts
    Member since:
    Jul 2007

    Posted 15 Mar 2010 Link to this post

    I just wondering how I would be able to implement the ability to enforce the file extension of a file when a user renames a file. Right now, if you rename a file it shows the user the entire filename (i.e. "NewFile.txt"), but if they write "NewFileName" in the rewrite dialog I lose the extension and it then becomes an unknown file. I've checked the documentation for the client-side and server-side and the control does tell you if a rename was performed, but no way of determining the file that was renamed nor the ability to change it if the extension was not included.

    Is there some way for me to examine the file before it's renamed, check the extension and then update the file being saved with the extension if it was removed?
  2. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 19 Mar 2010 Link to this post

    Hi,

    You can use the server-side ItemCommand event of the RadFileExplorer to intercept the rename operation and change the new name if you don't want it. For example:

    protected void Page_Load(object sender, EventArgs e)
    {
        RadFileExplorer1.ItemCommand += new RadFileExplorerEventHandler(RadFileExplorer1_ItemCommand);
    }
     
    protected void RadFileExplorer1_ItemCommand(object sender, RadFileExplorerEventArgs e)
    {
        if (e.Command == "MoveFile" || e.Command=="MoveDirectory")
        {
            //check e.newPath and change it if needed
            string newPath = e.NewPath;
        }
    }

    Note that the rename operation in the RadFileExplorer is essentially a move operation to the same parent folder but with a different name. This is why in the event handler you need to execute your code for "MoveFile" and "MoveDirectory" commands.

    Greetings,
    Lini
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top