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

rename file on upload

0 Answers 69 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Atlas
Top achievements
Rank 1
Atlas asked on 14 Oct 2010, 01:16 AM
I had to create a support ticket to find out how to override the save as function, because I needed to strip all special characters from the file name. There are demos that show creating a custom provider, but they involve a lot of code and methods, and I only wanted to override the file save.
Telerik gave me a great solution, so I thought I would pass it on. I am not sure why they don't make public the resolutions to these support tickets in some generic way, it seems like it would be useful to a lot of us out there.
anyways, here is the class file for the custom provider:
using System.IO;
using System.Web;
using Telerik.Web.UI;
using Telerik.Web.UI.Widgets;
  
namespace Blah.BlahBlah
{
    public class CustomFileSystemProvider : FileSystemContentProvider
    {
        public CustomFileSystemProvider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag)
            : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag)
        {
  
        }
  
        public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments)
        {
            string fileName = Helper.RemoveSpecialCharacters(file.GetName());
  
            string pathToSave = Path.Combine(Context.Server.MapPath(path), fileName);
            file.SaveAs(pathToSave);
  
            string virtualPath = VirtualPathUtility.Combine(path, fileName);
            return virtualPath;
        }
    }
}
And it is implemented on the individual control like so:
FileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomFileSystemProvider).AssemblyQualifiedName;

Hopefully, this can be helpful to somebody.

No answers yet. Maybe you can help?

Tags
FileExplorer
Asked by
Atlas
Top achievements
Rank 1
Share this question
or