C#判断文件类型
2011-04-28 09:43
260 查看
下面的函数可以判断是否为图片,里面的fileClass 你自己根据注释添加其它的类型 C# code private bool IsPicture(string filePath)//filePath是文件的完整路径 { try { FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(fs); string fileClass; byte buffer; byte[] b=new byte[2]; buffer = reader.ReadByte(); b[0] = buffer; fileClass = buffer.ToString(); buffer = reader.ReadByte(); b[1]=buffer; fileClass += buffer.ToString(); reader.Close(); fs.Close(); if (fileClass == "255216 ")//255216是jpg;7173是gif;6677是BMP,13780是PNG;7790是exe,8297是rar { return true; } else { return false; } } catch { return false; } }
相关文章推荐
- c#真正判断文件类型
- C#根据文件流判断文件类型
- C# 窗体拖拽文件类型判断
- C#判断文件类型
- C#判断文件的真正类型,不根据扩展名判断
- C# 如何后台判断 file控件上传的文件类型
- C#磁盘类型判断 所有磁盘遍历出所有文件夹及文件夹路径 所有文件及文件路径
- C# 通过HttpWebRequest 创建连接获取文件大小 判断Http类型的文件是否存在
- C#通过系统API判断网络连接类型及状态
- C#文件相同性判断
- js判断上传文件的类型
- nodejs文件上传类型判断
- C#判断常见类型格式是否正确的类
- c# 判断指定文件是否存在
- 用ASP.net判断上传文件类型的三种方法
- C# Directory.GetFiles()获取多个类型格式的文件
- php里的unpack函数判断上传文件的类型
- C# 判断文件是否文本文件
- 深入C#判断操作系统类型的总结详解(转载)