检查文件是否是txt
/// <summary> /// Checks the file is textfile or not. /// </summary> /// <param name="fileName"> Name of the file. </param> /// <returns></returns> public static bool CheckIsTextFile(string fileName) { FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); bool isTextFile = true; try { int i = 0; int length = (int)fs.Length; byte data; while (i < length && isTextFile) { data = (byte)fs.ReadByte(); isTextFile = (data != 0); i++; } return isTextFile; } catch (Exception ex) { throw ex; } finally { if (fs != null) { fs.Close(); } } }
这个是问题的,无法跳过html,csv.