Since the upload is a picture, then you should upload the file before the verification, to see if the upload is not a picture file
Recent work needs to do a upload image function, since the upload is a picture, then should be uploaded before the file to verify that you want to upload is not a picture file. So verify the format of the selected file before uploading. Upload the picture because the server resources are limited, often will stipulate the maximum number of pictures, so before uploading to the picture size of a verification. Let's do these two validations today. Verify the file type to see if the selected file is a picture: code as follows://File type: protected bool Isallowablefiletype (string FileName) { //read from Web.config file type restriction string stringstrfiletypelimit; Stringstrfiletypelimit = configurationmanager.appsettings["Picturetye"]. ToString (); ///The current file name extension is contained in this string Response.Write (FileName + stringstrfiletypelimit); if ( Stringstrfiletypelimit.indexof (Filename.tolower ())!=-1) { return true; } else { return false; } } Verify the file size to see if the file has exceeded the maximum limit: code as follows://File size public bool Isallowablefilesize (long filecontentlength) { //read from web.config to determine file size limitations Int32 Doubleifilesizelimit ; doubleifilesizelimit = Convert.ToInt32 (configurationmanager.appsettings["FileSizeLimit"]); // Determine if the file exceeds the limit if (doubleifIlesizelimit > Filecontentlength) { return true; } else { return false; }&NB Sp } is the configuration file settings, which specify the extension and size of the uploaded file. Code is as follows: <appSettings> <add key= "Picturetye" value= ". Jpg|. Gif|. Png|. bmp|. Jpeg| " /> <add key= "Filesizelimit" value= "512000"/> </appSettings> code is simple, As long as the two methods before uploading, you can upload the file for a simple verification, not only applicable to the image upload, other documents, as long as you need to modify the configuration file.