Restricting Uploaded Files by Regular Expression

Thread is closed for posting
4 posts, 0 answers
  1. BA42AFB8-BCB6-468E-A05F-408D0474EA29
    BA42AFB8-BCB6-468E-A05F-408D0474EA29 avatar
    30 posts
    Member since:
    Aug 2004

    Posted 07 Jun 2010 Link to this post


    Requirements

    RadControls version Q1 2010

    .NET version 3.5

    Visual Studio version 2010

    programming language VB.NET

    browser support

    all browsers supported by RadControls

    TITLE
    Retrieving the name of the uploaded file(s) and directory for restricting file upload/rename or directory creation/rename checking the name by Regular Expression

    PROJECT DESCRIPTION 
    There is not a built in function in Rad File Explorer (that is the component inside Rad Editor dialogs) to inhibit uploading/renaming file name or creating/renaming directory with strange chars like "$" or "%" and so on. It happens that in a CMS solution built with RadControls the user loads file with these chars and even if windows server accepts them the file system could be "dirty" and full of strange file. The same thing happens with the creation of directory or renaming of files.

    In this solution I created a new class derived from Telerik.Web.UI.Widgets.FileSystemContentProvider that though a simple regular expression check what the user loads or renames and in case the names are not compatible with the rules of the website answer change automatically changes the name and upload or advises the user with an alert and of course cancel the operation itself.
    I commented all the code and I created a region called "customization" where the developer can change the behavior of the message of the class. In depth:

    _strRegex   >>>> The regular expression that corresponds to the website rules
    _strChaneForInvalidChar >>>> The char that substitutes the invalid chars find by the regex
    _blnConsiderOverWriteFilesChangingName >>>> Works only on the upload file, represents if the developer wants to check about an existing file
    _TypeAdvise = Enum, the developer can check if he want to advise the user with an alert or change the name directly
    _strAlertForRenameFile = Message for the alert about rename file
    _strAlertForUploadFile  = Message for the alert about upload file
    _strAlertForAlreadyExistingFile = Message for the alert about already existing file, it happens when the file uploaded is not the same into the directory (the component block it) but with changing by the code could be in the dir.
    _strAlertForRenameDir  = Message for the alert about rename directory
    _strAlertForCreateDir  = Message for the alert about create  directory


    There is also a function called "ReturnCorrectString" that the developer have to change for implementing its own changing logic for require the website's rule.
  2. DF60784D-55A5-4263-9F10-A12FA48C9ADC
    DF60784D-55A5-4263-9F10-A12FA48C9ADC avatar
    14477 posts
    Member since:
    Apr 2022

    Posted 07 Jun 2010 Link to this post

    Hi Gianluca,

    Thank you for sharing your useful solution with the community. I updated your Telerik points for your contribution.

    Best wishes,
    Rumen
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. 463D4854-FC17-4B17-A5B1-3182E5080AB1
    463D4854-FC17-4B17-A5B1-3182E5080AB1 avatar
    4 posts
    Member since:
    Aug 2013

    Posted 28 Aug 2013 Link to this post

    I know this post is not recent, but actually i have a problem with special chars, if one file name contains special chars, the imageManager is not working to display the image in the preview, is there any way to force the control to load the image in the preview ? i cannot rename the images that contains special chars in the file name, because these images are used to send emails and if on of these images has been used in a thread then the image won't be loaded, this is the reason i want to find some solution for this.

    Thanks and hope there is a workaround...


  4. E0B8B146-EE4E-4C4D-A1D5-BB2E6C929855
    E0B8B146-EE4E-4C4D-A1D5-BB2E6C929855 avatar
    2425 posts
    Member since:
    Apr 2022

    Posted 29 Aug 2013 Link to this post

    Hi Vazqusa,

    I have just answered your other forum thread on the subject - please, refer it here.

    Sincerely yours,
    Veselina Raykova
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.