This sounded like such a simple request but I simply can't figure it out.
I want to prevent the user from selecting certain file types (I'm trying to implement a blacklist type of validation rather than the whitelist method that the telerik control comes with out-of-the-box).
OK, so there's no set_cancel() method for OnClientFileSelected. A shame, but moving on.
I though, OK, if they select an invalid file type, I'll just remove it, so came up with this ....
This doesn't work, the attempt to delete the file input generates an error reporting "HtmlPage_NotEnabled" in a line of javascript that calls Content.Page.MarshalUploads(). This appears to be something to do with Silverlight, but I can't stop it from happening.
Working to a deadline, I moved on.
So, I thought, "OK, if I can't stop 'em selecting these files, I can at least, stop 'em from being uploaded".
So, I modified the code to this ...
Tried that and Yay! the file is mared red as a failed upload!
Then I click on the button on my page to actually do the postback and process the uploaded files. Get what I find in my server-side list of uploaded files, yep. The file that I had set cancel on. What's more it shows it IsValid as true.
Is this God's punishment for me working on a Sunday? If it is, he's picking on the wrong bloke, I have no choice; he should go smite the guy who said I had to.
If anyone can offer any suggestions as to what I'm doing wrong, I'd love to hear 'em.
--
Stuart
I want to prevent the user from selecting certain file types (I'm trying to implement a blacklist type of validation rather than the whitelist method that the telerik control comes with out-of-the-box).
OK, so there's no set_cancel() method for OnClientFileSelected. A shame, but moving on.
I though, OK, if they select an invalid file type, I'll just remove it, so came up with this ....
var
fileExtensionBlacklist =
"<%=DisallowedFileTypes %>"
;
function
OnClientFileSelected(sender, e)
{
if
(
"<%=UseBlacklist %>"
==
"True"
)
{
var
selectedFileName = e.get_fileName();
var
selectedExtension = selectedFileName.split(
"."
).pop();
if
(fileExtensionBlacklist !=
""
&& fileExtensionBlacklist.indexOf(selectedExtension) > -1)
{
try
{ $find(
"<%=RadAsyncUpload1.ClientID %>"
).deleteFileInputAt(e.get_rowIndex()); }
catch
(ex) { }
}
}
}
function
OnClientFileUploadFailed(sender, e)
{
e.set_handled(
true
);
}
Working to a deadline, I moved on.
So, I thought, "OK, if I can't stop 'em selecting these files, I can at least, stop 'em from being uploaded".
So, I modified the code to this ...
function
OnClientFileUploading(sender, e)
{
if
(
"<%=UseBlacklist %>"
==
"True"
)
{
var
selectedFileName = e.get_fileName();
var
selectedExtension = selectedFileName.split(
"."
).pop();
if
(fileExtensionBlacklist !=
""
&& fileExtensionBlacklist.indexOf(selectedExtension) > -1)
{
e.set_cancel(
true
);
}
}
}
Then I click on the button on my page to actually do the postback and process the uploaded files. Get what I find in my server-side list of uploaded files, yep. The file that I had set cancel on. What's more it shows it IsValid as true.
Is this God's punishment for me working on a Sunday? If it is, he's picking on the wrong bloke, I have no choice; he should go smite the guy who said I had to.
If anyone can offer any suggestions as to what I'm doing wrong, I'd love to hear 'em.
--
Stuart