limit upload image file dimension

2 posts, 0 answers
  1. sf
    sf avatar
    103 posts
    Member since:
    Apr 2009

    Posted 29 Nov 2012 Link to this post

    I restricted my fileexplorer to only accept images using SearchPattern property.
    Is it possible that we can also control the dimension of the image file that gets uploaded? e.g. only allow people to upload image files with dimension of 500x600.

    thanks in advance
  2. Vessy
    Vessy avatar
    1663 posts

    Posted 03 Dec 2012 Link to this post


    Currently the desired functionality is not available out of the box but you could achieve it by subclassing the existing FileSystemContentProvider and overriding the StoreFile() method. In order to take the dimensions of the uploaded images, you could create an instance of the EditableImage class from the uploaded file's memory stream and access them in a similar way:
    public partial class FileExplorer : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            RadFileExplorer1.Configuration.ContentProviderTypeName = typeof(CustomFileSystemProvider).AssemblyQualifiedName;
    public class CustomFileSystemProvider : Telerik.Web.UI.Widgets.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)
            var maxHeight = 500;
            var maxWidth = 600;
            string targetPath = Path.Combine(path, name);
            var physicalPath = MapPath(targetPath);
            var editableImage = new EditableImage(file.InputStream);
            var height = editableImage.Height;
            var width = editableImage.Width;
            if (height > maxHeight || width > maxWidth)
                return string.Empty;
            //existing file will be overwritten!
            return targetPath;

    the Telerik team
    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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top