Function class for checking file types:
Using System;
Using System. Collections. Generic;
Using System. Web. UI. WebControls;
Using System. IO;
Namespace 0x001. Pack
{
Public enum FileExtension
{
. JPG = 255216,
GIF = 7173,
BMP = 1, 6677,
PNG = 1, 13780
// 255216 jpg;
// 7173 gif;
/// 6677 bmp,
// 13780 png;
// 7790 exe dll,
// 8297 rar
// Xml 6063
// Html 6033
// 239187 aspx
// 117115 cs
// Js 119105
/// 210187 txt
// 255254 SQL
}
Public class FileValidation
{
Static bool IsAllowedExtension () static bool IsAllowedExtension (FileUpload fu, FileExtension [] fileEx)
{
Int fileLen = fu. PostedFile. ContentLength;
Byte [] imgArray = new byte [fileLen];
Fu. PostedFile. InputStream. Read (imgArray, 0, fileLen );
MemoryStream MS = new MemoryStream (imgArray );
System. IO. BinaryReader br = new System. IO. BinaryReader (MS );
String fileclass = "";
Byte buffer;
Try
{
Buffer = br. ReadByte ();
Fileclass = buffer. ToString ();
Buffer = br. ReadByte ();
Fileclass + = buffer. ToString ();
}
Catch
{
}
Br. Close ();
Ms. Close ();
Foreach (FileExtension fe in fileEx)
{
If (Int32.Parse (fileclass) = (int) fe)
Return true;
}
Return false;
& Nbs