Dale Palmer
Top achievements
Rank 1
Dale Palmer
asked on 15 Jul 2009, 09:41 AM
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
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
7 Answers, 1 is accepted
0
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:
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.
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.
0
Dale Palmer
Top achievements
Rank 1
answered on 15 Jul 2009, 12:39 PM
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
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
0
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:
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.
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.
0
Dale Palmer
Top achievements
Rank 1
answered on 17 Jul 2009, 02:40 PM
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
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
0
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.
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.
0
moegal
Top achievements
Rank 1
answered on 04 Feb 2014, 07:58 PM
how can I add the class myprovider globally? Or will I need to add it to each page that uses the editor?
Marty
Marty
0
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
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.