1 Configure the following in Web. config: 2 3 <Deleetask> 4 5 <Add key = " Filetype " Value = " .Doc,.xls,.txt,.rar " /> 6 <Add key = " Picturetye " Value = " . Jpg |. gif |. PNG |. BMP |. PSD |. SVG | " /> 7 <Add key = " Filesizelimit " Value = " 10240 " /> 8 9 </Appsettings> 10 11 The methods in the. CS file are as follows: 12 13 File Size judgment: 14 15 Public Bool Isallowablefilesize () 16 { 17 // Read from web. config to determine the file size limit 18 Double Ifilesizelimit = convert. toint32 (configurationmanager. receivettings [ " Filesizelimit " ]); 19 // Determine if the file exceeds the limit 20 If (Ifilesizelimit> Fileupload1.postedfile. contentlength) 21 { 22 Response. Write ( " File " ); 23 Return True ; 24 } 25 Else 26 { 27 Response. Write ( " The file is too large. " ); 28 Return False ; 29 } 30 } 31 32 File Type: 33 34 Protected Bool Isallowablefiletype ( String Filename) 35 { 36 // Read from web. config to determine the file type Limit 37 String Strfiletypelimit = configurationmanager. appsettings [ " Filetype " ]. Tostring (); 38 // Whether the current file extension is included in this string 39 If (Strfiletypelimit. indexof (path. getextension (filename). tolower ())! =- 1 ) 40 { 41 Return True ; 42 } 43 Else 44 Return False ; 45 }