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