Exemplo n.º 1
0
		public static bool IsDataHTML(BinaryData fileData)
		{
			byte[] byteArray = new byte[4];
			using (Stream str = fileData.AsStream())
			{
				str.Read(byteArray, 0, 4);
				Encoding encoding = FindEncoding(ref byteArray);

				string dataString = fileData.AsString(10240, encoding).ToLowerInvariant();
				// Trim off byte order marks from the beginning of the string
				dataString = dataString.TrimStart(new char[] { '\xFEFF', '\xFFFE' });

				return IsStringHTML(dataString);
			}
		}
Exemplo n.º 2
0
		public static bool IsRtfFile(BinaryData data)
		{
			if (data.Length <= 5)
			{
				return false;
			}

			try
			{
				string headerstring = data.AsString(5, Encoding.UTF8);
				return headerstring.CompareTo(@"{\rtf") == 0;
			}
			catch (Exception)
			{
				return false;
			}
		}
Exemplo n.º 3
0
 bool IsPdfFileWithHtmlTags(BinaryData binaryData)
 {
     var content = binaryData.AsString(1024, Encoding.ASCII).ToLower();
     
     // Find <html>...</html>%PDF-1.4
     // Expect file content to start with html open tag 
     // Expect pdf identifier to follow the html close tag       
     return (content.StartsWith("<html>") && content.Contains("</html>%pdf"));
 }
Exemplo n.º 4
0
		private static string DataAsString(BinaryData binaryData, Encoding encoding)
		{
			if (null == binaryData)
				return string.Empty;

			return binaryData.AsString(16, encoding);
		}