Uploadfile format check

Source: Internet
Author: User
Code
Public   Bool Canupload ( String Filename)
{
If ( String . Isnullorempty (filename ))
{
Lblmsg. Text =   " Please select files! " ;
Return   False ;
}
If (Filename. indexof ( " ' " ) >   - 1 )
{
Lblmsg. Text =   " File Name shocould exclud qotation marks! " ;
Return   False ;
}
If (Filename. indexof ( " . " ) =   - 1 )
{
Lblmsg. Text =   " Unrecognizable file! " ;
Return   False ;
}
Int Contentsize = Fileupload. postedfile. contentlength;
If (Contentsize >   4470784 )
{
Lblmsg. Text =   " File size is larger than 4 MB! " ;
Return   False ;
}
If (Contentsize =   0 )
{
Lblmsg. Text =   " File size is 0! " ;
Return   False ;
}

// Attachment type does not allow upload
String Filetype = Filename. substring (filename. lastindexof ( " . " ) +   1 ). Toupper ();
Bool Canuploadfiletype =   False ;
// Allowed types of Upper Limit
String [] Canfilestype =   New   String [] { " JPG " , " JPEG " , " PNG " , " PDF " , " PPT " , " Txt " , " Xls " , " Doc " };
For ( Int I =   0 ; I < Canfilestype. length; I ++ )
{
If (Canfilestype [I] = Filetype)
{
Canuploadfiletype =   True ;
}
}
If (Canuploadfiletype =   False )
{
Lblmsg. Text =   " Unacceptable file! " ;
Return   False ;
}
Return   True ;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.