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 ;
}