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

How to block certain file extensions with RadAsyncupload

6 Answers 1084 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Praveen kumar
Top achievements
Rank 1
Praveen kumar asked on 30 Jun 2015, 05:57 PM

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......

6 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 03 Jul 2015, 08:14 AM
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
0
Praveen kumar
Top achievements
Rank 1
answered on 07 Jul 2015, 03:08 PM

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

0
Praveen kumar
Top achievements
Rank 1
answered on 20 Jul 2015, 06:57 PM

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
0
Plamen
Telerik team
answered on 21 Jul 2015, 01:48 PM
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
0
Praveen kumar
Top achievements
Rank 1
answered on 21 Jul 2015, 04:33 PM

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.

0
Plamen
Telerik team
answered on 23 Jul 2015, 05:51 AM
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
Tags
Upload (Obsolete)
Asked by
Praveen kumar
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Praveen kumar
Top achievements
Rank 1
Share this question
or