Configure in Web.config:
Copy Code code as follows:
<appSettings>
<add key= "FileType" value= "Doc,.xls,.txt,.rar"/>
<add key= "Picturetye" value= ". Jpg|. Gif|. Png|. bmp|. psd|. Svg| " />
<add key= "Filesizelimit" value= "10240"/>
</appSettings>
Method implementation in the. cs file:
File size judgment:
Copy Code code as follows:
public bool Isallowablefilesize ()
{
Read from web.config to determine file size limitations
Double ifilesizelimit = Convert.ToInt32 (configurationmanager.appsettings["Filesizelimit"));
To determine if a file exceeds the limit
if (Ifilesizelimit > FileUpload1.PostedFile.ContentLength)
{
Response.Write ("File Just Right");
return true;
}
Else
{
Response.Write ("File too large");
return false;
}
}
File type:
Copy Code code as follows:
protected bool Isallowablefiletype (string FileName)
{
Read from web.config to determine file type limits
String strfiletypelimit = configurationmanager.appsettings["FileType"]. ToString ();
Whether the current file name extension is contained in this string
if (Strfiletypelimit.indexof path.getextension (FileName). ToLower ())!=-1)
{
return true;
}
Else
return false;
}