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

Restrict certain characters in uploaded files

1 Answer 248 Views
Editor
This is a migrated thread and some comments may be shown as answers.
James Rintoul
Top achievements
Rank 1
James Rintoul asked on 06 Feb 2009, 02:01 PM

We need a way to stop end users uploading images through the image manager that have certain characters in the file name. If a user uploads a file named with spaces or special characters it's a nightmare for our application to deal with it, so we want to prevent the problem at the root cause.

Is there a way to do this? Can the file browser filter out these files or is there some validation event we can use before the upload begins?

I think the FileBrowserContentProvider *may* be want  but I only need to override the default behaviour in one place rather than do a completely custom implementation.

Any advice much appreciated.

Thanks,
James.




1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 10 Feb 2009, 08:16 AM
Hi James,

My suggestion is to implement a FileSystemContentProvider, which will require to override only the functions that you would like. Here is an example how override only the StoreFile method which is fired when saving a file:

public class MyContentProvider : Telerik.WebControls.RadEditorUtils.FileSystemContentProvider
 {
        public MyContentProvider(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(HttpPostedFile file, string path, string name, params string[] arguments)
        {
            //add here your validation code for file upload
        }
    }

    private void Page_Load(object sender, System.EventArgs e)
    {
        RadEditor1.FileBrowserContentProviderTypeName = typeof(MyContentProvider).AssemblyQualifiedName;
    }

Feel free to modify the code to fit your scenario.

Greetings,
Rumen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Editor
Asked by
James Rintoul
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or