如何检查给定文件是否为正确的word文件格式?
我正在使用 C# 开发一个应用程序来处理 MSWord 文件。当我传递无效的 .doc 文件作为输入时,我的应用程序挂起。例如,如果我有一个 foo.pdf 文件,并在更改其扩展名 (foo.doc) 后将其传递给我的应用程序。 在尝试打开文件之前是否可以检查文件是否是有效的文档文件? 请赐教!!!!
提前致谢
I am developing one application using C# for processing MSWord files. My application gets hang when I pass invalid .doc file as an input. For example, if I have one foo.pdf file and I pass it to my application after changing its extension (foo.doc).
Is it possible to check whether file is valid doc file before trying to open it?
Please enlighten !!!!
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用Office PIA处理word文件,您可以首先获取文档的元数据信息。
如果它返回一些元数据,它应该是一个有效的 Word 文档。
读取word文档中的元数据请参考以下内容:
http: //bytes.com/topic/c-sharp/answers/757466-c-app-reading-modifying-ms-office-document-meta-data
希望这比处理整个无效文档更快。
希望有帮助!
If you are using Office PIA to process the word files you could first get the metadata information of the document.
If it returns some metadata it should be a valid word document.
Refer the following for reading metadata in word documents:
http://bytes.com/topic/c-sharp/answers/757466-c-app-reading-modifying-ms-office-document-meta-data
Hope that would be quicker then processing the whole invalid document.
Hope it helps!