This is a migrated thread and some comments may be shown as answers.

Rename file by forcing file extension

1 Answer 61 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
robertw102
Top achievements
Rank 1
robertw102 asked on 15 Mar 2010, 07:56 PM
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?

1 Answer, 1 is accepted

Sort by
0
Lini
Telerik team
answered on 19 Mar 2010, 12:09 PM
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.
Tags
FileExplorer
Asked by
robertw102
Top achievements
Rank 1
Answers by
Lini
Telerik team
Share this question
or