Thanks,
Jim
5 Answers, 1 is accepted
You can set the AllowedFileExtensions property which lists the valid file extensions for uploaded files. Checkout the following links for more information.
Integrated Validation
The following example shows how to prevent the postback if the files to upload are invalid.
OnClientSubmitting
Hope this helps
-Princy.
Thanks,
Jim
You can use a CustomValidator control and in its ClientValidationFunction you can check if the extensions of the selected files are blocked (exe, pif, etc.). Based on these checkings you can invalidate the result.
All the best,
Veselin Vasilev
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
function
ValidateSubmission(source, eventArgs)
{
var upload = $find("<%= ruUpload.ClientID %>");
var inputs = upload.getFileInputs();
var cont = 'true';
for (i = 0; i < inputs.length; i++)
{
var inp = inputs[i].value;
if (inp.indexOf('.exe') > -1 ||
inp.indexOf(
'.vbs') > -1 ||
inp.indexOf(
'.bat') > -1)
cont =
'false'
}
if(cont == 'false')
{
var cnt = inputs.length;
for(i = 0; i<cnt;i++)
{
upload.clearFileInputAt(i);
}
alert(
"Submission blocked: one or more files have the wrong type! File extension .exe, .vbs and .bat not allowed.");
}
else
{
var exts = upload.get_allowedFileExtensions();
if(exts.length > 0)
{
eventArgs.set_cancel(!upload.validateExtensions());
if (eventArgs.get_cancel())
{
for(i=0;i<inputs.length;i++)
{
upload.clearFileInputAt(i);
}
alert(
"Submission blocked: one or more files have the wrong type!");
}
}
}
}
Thanks for all of your help.
<asp:CustomValidator ID="cvUploader" runat="server" Display=Dynamic ClientValidationFunction="ClientValidateUpload" ErrorMessage="At least one file should be selected."></asp:CustomValidator> <telerik:RadScriptBlock ID="RadScriptBlock3" runat="server"> <script language="javascript" type="text/javascript"> function ClientValidateUpload(source, arguments) { u = $find(uTelUploaderID); if (u.getFileInputs().length === 1) { arguments.IsValid = false; } } </script> </telerik:RadScriptBlock> |
uTelUploaderID holds the clientID of the RadUpload.the event is not firing at all. and i am not using server validate.