在asp.net中打开word文件 [英] open word file in asp.net

查看:106
本文介绍了在asp.net中打开word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨。

我想通过我的应用程序打开一个word文件。这个单词word文件存储在我的应用程序的文件夹中。因为我已经使用了这个代码.....当我正在通过visual studio运行时,它运行正常。但在通过iis运行时显示错误'对象引用未设置为对象的实例'。所以请建议我做什么

hi.
I want to open a word file through my application.this word word file is stored inside a folder of my application. for that i have used this code.....it is working fine when i am running throughh visual studio. but showing error 'Object reference not set to an instance of an object' when running through iis. so please suggest me what to do

try
 {
string filepath= Server.MapPath("~/Uploadhtml/Functions Report23082012_130108.doc");                
Microsoft.Office.Interop.Word.ApplicationClass WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
 object fileName = filepath;
 object readOnly = false;
 object isVisible = true;
 object missing = System.Reflection.Missing.Value;
 WordApp.Visible = true;
 Microsoft.Office.Interop.Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
 aDoc.Activate();
  }
 catch(Exception e)
   {
  string script = "alert('Html error found.');";
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Button3, this.GetType(), "Test", script, true);
}

推荐答案

为了使代码有效,它需要三件事:



1)IIS服务器需要安装相应版本的Word。

2)你需要一个非常宽容,友好的网络管理员。

3)你需要让你的用户坐在IIS服务器PC前面,而不是他自己的。



后者可能很难 - 我建议你试验远程传送。



当你在你的开发机器上测试它时,它工作是因为你安装了Word,而服务器和客户端都在同一台PC上。所以看起来它工作正常,但实际上Word实例是在服务器上打开的,而不是客户端。在生产中,两台PC不同,但Word实例仍将在服务器上打开,而不是客户端 - 因此他将无法随时看到它。



您无法从服务器上运行客户端PC上的任何应用程序(除非在非常特殊的条件下,几乎肯定不会在现实世界中应用)。安全性不会允许它,即使有办法判断客户端实际上是PC,而不是Mac,Android平板电脑,或支持网络的冰箱,或......
In order for that code to work, it needs three things:

1) The IIS Server needs to have the appropriate version of Word installed.
2) You need to have a very tolerant, and friendly web administrator.
3) You need to get your user to sit in front of the IIS server PC, instead of his own.

The latter may prove difficult - I suggest you experiment with teleportation.

When you tested it on your development machine, it worked because you had Word installed, and the server and client were both on the same PC. So it looked like it worked fine, but in practice the Word instance was opened on the Server, not the Client. In production teh two PCs are different, but the Word instance will still open on the Server, not the client - so he won't be able to see it at any time.

You cannot run any application on the Client PC from the Server (except under very special conditions which almost certainly will not apply in the real world). Security will not allow it, even if there was a way to tell if the client was actually a PC, rather than a Mac, or an Android tablet, or a web-enabled fridge, or...

如果您想保存上面提到的Griff的麻烦,那么您可以试试这个 Word .NET [ ^ ]组件。它解决了你的每一个麻烦。
If you wish to save the troubles Griff mentioned above, then you can try with this Word .NET[^] component. It solves your every trouble.


这篇关于在asp.net中打开word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆