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

[Solved] Change name of uploaded image

1 Answer 85 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 07 Aug 2009, 05:48 PM
Hello,

Is there a way to change the name of an uploaded image?  For example the image uploaded maybe named "figure 1.jpg" and I would like to change it to "figure-1.jpg".

Thank You,
Alex

1 Answer, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 11 Aug 2009, 01:21 PM
Hello Alex,

For the time being you need to implement your custom provider and override the StoreFile method. In this method you could change the uploaded file names. in your case I recommend you to use the following code :

namespace CustomProvider  
{  
    public class CustomFileSystemContentProvider : FileSystemContentProvider  
    {  
        public CustomFileSystemContentProvider(HttpContexts context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)  
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)  
        {  
            ProcessPaths(ViewPaths);  
            ProcessPaths(UploadPaths);  
            ProcessPaths(DeletePaths);  
            SelectedUrl = RemoveProtocolNameAndServerName(GetAbsolutePath(SelectedUrl));  
        }  
        // Override the store file function ;  
        public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)  
        {  
            string newFileName = DateTime.Now.Second.ToString() + name;// New name ;  
            string targetFullPath = Path.Combine(path, newFileName);  
            file.SaveAs(Context.Server.MapPath(targetFullPath), true);  
            return targetFullPath;  
        }  
    }  
 
The highlighted code produce a new name of the uploaded file. Then you need to use this provider in the RadFileEcplorer's configuration :

RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomProvider.CustomFileSystemContentProvider).AssemblyQualifiedName; 

In the next releases we plan to allow renaming of the file in the OnItemCommand server event of the FileExplorer control.

I hope this helps.


Greetings,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
Alex
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Share this question
or