public static bool IsPdf(HttpPostedFileBase DocumentUpload)
{
var pdfString = "%PDF-";
var pdfBytes = Encoding.ASCII.GetBytes(pdfString);
var len = pdfBytes.Length;
int FileLen;
System.IO.Stream MyStream;
FileLen = DocumentUpload.ContentLength;
byte[] buffer = new byte[len];
// Initialize the stream.
MyStream = DocumentUpload.InputStream;
// Read the file into the byte array.
if (FileLen >= len)
{
MyStream.Read(buffer, 0, len);
}
else
{
MyStream.Read(buffer, 0, FileLen);
}
return(pdfBytes.SequenceEqual(buffer));
}