ImageManager Remove Spaces From Folder Names

8 posts, 0 answers
  1. Dale Palmer
    Dale Palmer avatar
    27 posts
    Member since:
    May 2008

    Posted 15 Jul 2009 Link to this post

    Hi

    Is it possible to remove spaces (replace them with underscores) from folder names when a user creates a new folder in the image upload dialog?

    Thanks
  2. Rumen
    Admin
    Rumen avatar
    14434 posts

    Posted 15 Jul 2009 Link to this post

    Hi Dale,

    You can also implement you own file system content provider and rename the uploaded files on the server. The following code demonstrates how to resize the images in the StoreFile function. You can use this method to rename the image files:

        protected void Page_Load(object sender, EventArgs e) 
        { 
            RadEditor1.ImageManager.ViewPaths = new string[]{"~/"}; 
            RadEditor1.ImageManager.UploadPaths = new string[] { "~/" }; 
            RadEditor1.ImageManager.ContentProviderTypeName = typeof(myprovider).AssemblyQualifiedName; 
        } 
     
        public class myprovider : Telerik.Web.UI.Widgets.FileSystemContentProvider 
        { 
     
            public myprovider(HttpContext context, string[] searchPatterns, string[] viewPaths, string[] uploadPaths, string[] deletePaths, string selectedUrl, string selectedItemTag) 
                : base(context, searchPatterns, viewPaths, uploadPaths, deletePaths, selectedUrl, selectedItemTag) 
            { 
            } 
     
            public bool ThumbnailCallback() 
            { 
                return false
            } 
     
            public override string StoreFile(UploadedFile file, string path, string name, params string[] arguments) 
            { 
     
                string result = base.StoreFile(file, path, name, arguments); 
     
                System.Drawing.Image.GetThumbnailImageAbort myCallback = 
                    new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); 
     
                string fileName = Path.Combine(path, name); 
                //Create a copy of the image with a different size 
                using (System.Drawing.Image originalImage = Bitmap.FromStream(file.InputStream)) 
                { 
                    using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(300, 300, myCallback, IntPtr.Zero)) 
                    { 
                        thumbnail.Save(Context.Server.MapPath(fileName)); 
                    } 
                } 
     
                return result; 
            } 
        } 




    Kind regards,
    Rumen
    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.
  3. Dale Palmer
    Dale Palmer avatar
    27 posts
    Member since:
    May 2008

    Posted 15 Jul 2009 Link to this post

    It's not the files that I need to rename its the folders that users can create in the ImageManager dialog.

    See screenshot below

    http://www.growstudio.co.uk/folder.jpg

    I want to remove any spaces in the name and replace them with underscores.

    Regards
  4. Rumen
    Admin
    Rumen avatar
    14434 posts

    Posted 17 Jul 2009 Link to this post

    Hi Dale,

    Thank you for the additional information. In this scenario you should override the CreateDirectory function and for example replace the space with _ underscore:

        protected void Page_Load(object sender, EventArgs e)  
        {  
            RadEditor1.ImageManager.ViewPaths = new string[]{"~/"};  
            RadEditor1.ImageManager.UploadPaths = new string[] { "~/" };  
            RadEditor1.ImageManager.ContentProviderTypeName = typeof(myprovider).AssemblyQualifiedName;  
        }  
      
        public class myprovider : Telerik.Web.UI.Widgets.FileSystemContentProvider  
        {  
      
            public myprovider(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  CreateDirectory(string path, string name) 
            { 
                name = name.Replace(" ","_"); 
                return base.CreateDirectory(path, name); 
            } 
        }  



    Greetings,
    Rumen
    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.
  5. Dale Palmer
    Dale Palmer avatar
    27 posts
    Member since:
    May 2008

    Posted 17 Jul 2009 Link to this post

    Thanks for your reply. That example works great except if I try to delete the new folder that i created then I keep getting a callback error. I have posted a screenshot of this error.

    This pop occurs as soon as the new folder is deleted.

    Callback Error
    Image Manager Error

    As you can see from the first screenshot I created a new folder called 'new 3 folder' and it correctly replaced the spaces with underscores but I'm presented with a new error.

    Regards
  6. Rumen
    Admin
    Rumen avatar
    14434 posts

    Posted 23 Jul 2009 Link to this post

    Hi Dale,

    You are using an older version of Telerik.Web.UI.dll. This problem is fixed in the latest Q2 2009 and my recommendation is to upgrade to it.

    For your convenience I have attached my test project.

    Best regards,
    Rumen
    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.
  7. moegal
    moegal avatar
    278 posts
    Member since:
    Jul 2007

    Posted 04 Feb 2014 in reply to Rumen Link to this post

    how can I add the class myprovider globally?  Or will I need to add it to each page that uses the editor?

    Marty
  8. Ianko
    Admin
    Ianko avatar
    1949 posts

    Posted 07 Feb 2014 Link to this post

    Hello Marty,

    Customized content providers cannot be used as a global configurations.

    Although you can always create a custom user control, which inherits the RadEditor class and define additional configuration by overriding the OnLoad, OnRender or OnInit events. You can find attached an example for such approach.

    Regards,
    Ianko
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top