Hello,
I am using igUpload control in my ASP.NET MVC3 project. I know it has a property allowedExtensions to set the allowed upload the files with these extensions, I want to know if there is a way to set some types of files cannot be uploaded, is there a property like notAllowedExtension? For example, I just do not want to user to upload .exe files, all other types are ok, how can I do that?
Best regards
Jason
Hi Jason,
You can use the allowedExtensions option in JavaScript on the client or the AllowedExtensions method on the ASP.NET MVC helper:
JavaScript - accepts an array of strings representing the allowed file extensions:
$('#upload').igUpload({ allowedExtensions: [ 'jpg', 'bmp' ], progressUrl: '/IGUploadStatusHandler.ashx' });
ASP.NET MVC Helper (Razor C#) - accepts a Generic List of strings representing the allowed file extensions:
@(Html.Infragistics().Upload() .ID("upload") .AllowedExtensions(new List<string> { "jpg", "bmp" }) .ProgressUrl("/IGUploadStatusHandler.ashx") .Render() )
If you would like to show an error message, you can handle the onError event in JavaScript and check for status code 2:
$("#upload").bind("iguploadonerror", function (e, ui) { if (ui.errorCode === 2) alert(ui.errorMessage); return; });
You can read more about the upload's API in the API documentation: https://www.igniteui.com/help/igupload-igupload
Hope that helps!