This code snippet to your razor view. Make sure you have keno implemented in project.
@(Html.Kendo().Upload().Events(e => e.Upload("onUpload"))
.Name("Files")
.Async(a => a.Save("CustomDropZoneSave", "controller")
.Remove("CustomDropZoneRemove", "controller")
.AutoUpload(true)
)
.Events(x => x.Success("onCustomDropZoneFileSuccess").Remove("onCustomDropZoneFileRemove"))
.ShowFileList(true)
.Multiple(false)
)
Standard extensions we should not allow to update, goes to js file,
const BlockedFileFomates = ["exe", "ade", "adp", "apk", "appx", "appxbundle", "bat", "cab", "chm", "cmd", "com", "cpl", "dll", "dmg", "ex", "ex_", "exe", "hta", "ins", "isp", "iso", "jar", "js", "jse", "lib", "lnk", "mde", "msc", "msi", "msix", "msixbundle", "msp", "mst", "nsh", "pif", "ps1", "scr", "sct", "shb", "sys", "vb", "vbe", "vbs", "vxd", "wsc", "wsf", "wsh"];
Bellow is JS function which will prevent to upload above extensions.,
function onUpload(e) {
var files = e.files;
$.each(files, function () {
if (BlockedFileFomates.includes(this.extension.toLowerCase().replace('.', ''))) {
//we do have this function to show toast message. use your way to show alert message.
/*func_CreateToastrNotification('info', `Blocked for security reasons!. Blocked extentions : ${BlockedFileFomates.toString()}`, `File formate ${this.extension.toLowerCase()} is not allowed.`);*/
alert(`File formate ${this.extension.toLowerCase()} is not allowed.`);
e.preventDefault();
}
});
}
Explanation:
We have initiate "onUpload" event while load the kendo "Upload".
important is ".Events(e => e.Upload("onUpload")" that it will execute when we try to upload any file.
BlockedFileFomates is constant which is holding the all extensions name which we gonna restricted.
js function onUpload will prevent the files to upload.