rename file on upload

1 posts, 0 answers
  1. Atlas
    Atlas avatar
    97 posts
    Member since:
    Jun 2009

    Posted 13 Oct 2010 Link to this post

    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);
                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.
Back to Top