Alert show when extension of FileUpLoads are not allowed
Posted
by
Vy Clarks
on Stack Overflow
See other posts from Stack Overflow
or by Vy Clarks
Published on 2013-11-04T15:50:34Z
Indexed on
2013/11/04
15:53 UTC
Read the original article
Hit count: 349
I have a asp FileUpload control in my aspx page.
And the code behind to check file's extension and then insert them into database:
private string Write(HttpPostedFile file, string table)
{
string fileNameMain = Path.GetFileName(file.FileName);
// check for the valid file extension
string fileExtension = Path.GetExtension(fileNameMain).ToLower();
if (fileExtension.Equals(".pdf") || fileExtension.Equals(".doc"))
{
...insert fileupload into database
}
else
{
LabelError.Text = "Extension of files are not allowed.";
return null;
}
}
With the code above, it checks the extension and then show the message "Extension of files are not allowed."
in a LabelError
if the fileupload is not allowed.
Now, I'm required to do the "check-extension
" in the other way: at the moment the client click and choose FileUpload, an alert
show "Extension of files are not allowed.
".
I need a way to make an alert show at the momment the FileUpload choosed in browser. Help!!!!
© Stack Overflow or respective owner