正文

判断一文件是word文档2007-11-25 23:41:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/31154.html

分享到:

判断一文件是word文档,用c#或vb.net语言 http://topic.csdn.net/u/20071116/22/6af67454-b6f3-4ba1-95f2-6ce6c527cb74.html C# code using System.Runtime.InteropServices; [DllImport("ntdll.dll")] public static extern int RtlCompareMemory(IntPtr Destination, IntPtr Source, int Length); // 比较两个内存块是否相同 private void button1_Click(object sender, EventArgs e) { byte[] vHead = new byte[] { 0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1 }; // Doc文件的头标志 FileStream vFileStream = new FileStream(@"c:\temp\temp.doc", FileMode.Open, FileAccess.Read); byte[] vBuffer = new byte[vHead.Length]; vFileStream.Read(vBuffer, 0, vBuffer.Length); // 读取文件的头信息 vFileStream.Close(); if (RtlCompareMemory(Marshal.UnsafeAddrOfPinnedArrayElement(vHead, 0), Marshal.UnsafeAddrOfPinnedArrayElement(vBuffer, 0), vHead.Length) == vHead.Length) { MessageBox.Show("估计是Word文档"); } }

阅读(3184) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册