如何检查给定文件是否为正确的word文件格式?

发布于 2024-09-04 06:19:24 字数 181 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

国粹 2024-09-11 06:19:24

如果您使用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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文