How to block certain file extensions with RadAsyncupload

Thread is closed for posting
7 posts, 0 answers
  1. Praveen kumar
    Praveen kumar avatar
    11 posts
    Member since:
    Jun 2015

    Posted 30 Jun 2015 Link to this post

    Hi All,

    I know , we have property called "AllowedFileExtensions" specify the allowed extensions. but i have list of extensions which need to be blocked like .ADE,ADP,BAS,BAT,CHM,CMD,COM,CPL,CRT,EXE,HLP,HTA,INF,INS,ISP,JS so on.....list goes upto 38 extensions. How to block this list of extensions for RadAsyncupload control......

  2. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 03 Jul 2015 Link to this post

    Hello,

    You can assign the extensions dynamically as for example in the code below:
    string[] allowedFileExtensions = new string[3] {"zip", "doc", "config"};
     RadAsyncUpload1.AllowedFileExtensions = allowedFileExtensions;

    Hope this will help you solve the issue.

    Regards,
    Plamen
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Praveen kumar
    Praveen kumar avatar
    11 posts
    Member since:
    Jun 2015

    Posted 07 Jul 2015 in reply to Plamen Link to this post

    Thanks for your response Plamen.....

    I have used the following java script function to full fill requirement.

    http://demos.telerik.com/aspnet-ajax/asyncupload/examples/validation/defaultcs.aspx

  5. Praveen kumar
    Praveen kumar avatar
    11 posts
    Member since:
    Jun 2015

    Posted 20 Jul 2015 in reply to Plamen Link to this post

    string[] allowedFileExtensions = new string[3] {"zip", "doc", "config"};
     RadAsyncUpload1.AllowedFileExtensions = allowedFileExtensions; 

    where should i use lines i mean in which event. if use in RadAsyncUpload1_FileUploaded event , how to stop or cancel upload
  6. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 21 Jul 2015 Link to this post

    Hi,

    You can set it at the beginning so Page_Load event may be suitable for this configuration.

    Regards,
    Plamen
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  7. Praveen kumar
    Praveen kumar avatar
    11 posts
    Member since:
    Jun 2015

    Posted 21 Jul 2015 in reply to Plamen Link to this post

    Thanks for response,

    Please provide me sample for your response.

    Actually ,My requirement goes like this , we dont have allowed list extensions (i mean we allowing all extensions except some which are in xml file ) , instead we have blocked list of file types/extensions. So i wrote java script which will check against the blocked list. should be removed from the upload file collection. So i wrote following java script.

     function OnClientFileSelected(sender, args)
               {

                   var currentFileName = args.get_fileName();
                   var fileExt = '.' + currentFileName.split('.').pop().toUpperCase();
                   if (!(IsValidFileType(fileExt))) {
                       // invalid file - inform user and remove
                       alert('"' + currentFileName + '" cannot be uploaded and will be removed.');
                       sender.deleteFileInputAt(args.get_rowIndex());
                       sender.deleteFileInputAt(currentFileName);
                   }

     function IsValidFileType(fileext) {

                   var request = new XMLHttpRequest();
                   request.open("GET", "InvalidFileExtensions.xml", false);
                   request.send();
                   var xml = request.responseXML;
                   var fileTypes = xml.getElementsByTagName("InvalidFileExtensionList");

                   for (var i = 0; i < fileTypes.length; i++) {
                       var names = fileTypes[i].getElementsByTagName("FileExtension");
                       for (var j = 0; j < names.length; j++) {
                           if (fileext == (names[j].childNodes[0].nodeValue)) {
                               return false;
                           }
                       }
                       return true;
                   }
               }

    this script is running fine. It is able to remove blocked file extensions from uploading (i.e. i mean in UI). But in target folder am able to see the blocked files. It means in Front end the blocked file types are removed from uploading list.but in backend it goes to target folder.

    for this reason i trying to block from server side. suggest whether i should solve my problem by going with server side or client script.

  8. Plamen
    Admin
    Plamen avatar
    2731 posts

    Posted 23 Jul 2015 Link to this post

    Hello,

    In such case you can try using the onFileUploaded event and check if the file has a correct extensions and set the isValid property accordingly.

    Hope this will help you solve the issue.

    Regards,
    Plamen
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017