Verifying the true format of uploaded files

Source: Internet
Author: User

1         /// <summary>2         ///verifying the true format of uploaded files3         /// </summary>4         /// <param name= "FileUpload" ></param>5         /// <returns></returns>6         Private BOOLvalidationfile (httppostedfile fileUpload)7         {8Httppostedfile file =FileUpload;9BinaryReader r =NewBinaryReader (fileupload.inputstream);Ten             stringBX =" "; One             bytebuffer; A             Try -             { -Buffer =r.readbyte (); theBX =buffer. ToString (); -Buffer =r.readbyte (); -BX + =buffer. ToString (); -             } +             Catch(Exception) -             { +Response.Write ("file format is wrong! "); A Response.End (); at             } -  -             BOOLisOK =false; -             foreach(intIteminchEnum.getvalues (typeof(fileextension))) -             { -                 if(item. ToString () = =BX) in                 { -isOK =true; to                      Break; +                 } -             } the  *             returnisOK; $         }Panax Notoginseng  -         /// <summary> the         ///true format of uploaded files +         /// </summary> A          Public enumfileextension the         { +JPG =255216, -GIF =7173, $BMP =6677, $PNG =13780 -             //COM = 7790, -             //EXE = 7790, the             //DLL = 7790, -             //RAR = 8297,Wuyi             //ZIP = 8075, the             //XML = 6063, -             //HTML = 6033, Wu             //ASPX = 239187, -             //CS = 117115, About             //JS = 119105, $             //TXT = 210187, -             //SQL = 255254, -             //BAT = 64101, -             //btseed = 10056, A             //RDP = 255254, +             //PSD = 5666, the             //PDF = 3780, -             //CHM = 7384, $             //LOG = 70105, the             //REG = 8269, the             //HLP = 6395, the             //DOC = 208207, the             //XLS = 208207, -             //DOCX = 208207, in             //XLSX = 208207, the            //txt:4950 the}

Verifying the true format of uploaded files

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.