在 IIS 7 中打开 MS Word 文档时出现错误,
我正在通过 Asp.Net 开发一些页面,其中包含打开和阅读一些 MS Word 文档,它在我的 VS 2010 上在其自己的本地主机上运行良好,但是当我将文件放在 wwwroot 下并通过 Inetmgr 运行页面时,我收到此错误:
此命令不可用,因为没有打开文档。
您认为问题出在哪里?我应该在 IIS 管理器中添加一些引用或编辑一些设置来处理 MS Word 文档吗?如何?谢谢:)
这就是我尝试打开和阅读名为 stopwords.doc 的文档的方式
static extractor()
{
try
{
ApplicationClass wordApp = new ApplicationClass();
string[] words;
char[] delimiterChars = { ' ', ',', '.', '\r', '\t', '\n' };
string filePath = "http://localhost:8777/stopwords.doc";
object file = filePath;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj);
Microsoft.Office.Interop.Word.Document doc1 = wordApp.ActiveDocument;
string m_Content = doc1.Content.Text;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
if (m_Content != null)
{
words = m_Content.Split(delimiterChars);
foreach (string s in words)
{
if (!stopwords.ContainsKey(s))
stopwords.Add(s, s);
}
}
}
catch (Exception)
{
throw;
}
}
I'm developing some pages by Asp.Net which contains opening and reading some MS word docs, it works well by my VS 2010 on its own localhost but when I put the files under wwwroot and run the pages by Inetmgr I get this error :
This command is not available because no document is open.
where do you think the problem is? shall I add some references or edit some setting in my IIS manager to work with MS word docs? how? thanks :)
and this is how I'm trying to open and read a doc called stopwords.doc
static extractor()
{
try
{
ApplicationClass wordApp = new ApplicationClass();
string[] words;
char[] delimiterChars = { ' ', ',', '.', '\r', '\t', '\n' };
string filePath = "http://localhost:8777/stopwords.doc";
object file = filePath;
object nullobj = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.Document doc = wordApp.Documents.Open(ref file,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj);
Microsoft.Office.Interop.Word.Document doc1 = wordApp.ActiveDocument;
string m_Content = doc1.Content.Text;
doc.Close(ref nullobj, ref nullobj, ref nullobj);
if (m_Content != null)
{
words = m_Content.Split(delimiterChars);
foreach (string s in words)
{
if (!stopwords.ContainsKey(s))
stopwords.Add(s, s);
}
}
}
catch (Exception)
{
throw;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,运行 Web 进程的帐户没有足够的操作系统权限来运行 Word 等 GUI 应用程序。在大多数情况下,这可能是一件好事,因为人们确实不应该从 Web 进程运行 GUI 应用程序。当 Word 弹出一个模式对话框,阻止整个站点并且没有人可以访问 Web 服务器并单击“确定”时,会发生什么情况。如果您必须阅读 Word 文档,那么图书馆是一个更好的解决方案。
尽管如此,在这里使用 word 毫无意义——您只是从文件中加载一些停用词。纯文本同样有效并且更容易处理。
Typically the accounts running web processes don't have enough os permissions to run GUI apps like Word. This is probably a good thing in most cases as one really shouldn't run GUI apps from web processes. What happens when word springs a modal dialog that blocks the entire site and no one is available to visit the web server and click OK. If you must read word docs, a library is a much better solution.
All that said, using word here makes zero sense -- you are just loading some stop words from a file. Plain text would be just as effective and vastly easier to deal with.
这不是有效的文件路径。
尝试将文件放入 Web 应用程序文件夹中,例如在部署 ASP.NET 应用程序的位置中创建一个名为 WordDocs 的文件夹,然后获取如下文件路径:
this is not a valid filepath.
try to put the file inside the web application folder, for example create a folder called WordDocs inside the place where you deployed your ASP.NET application then get the file path like this: