Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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);
}
Posted
Updated 22-Aug-12 23:33pm
v2
Comments
Anuja Pawar Indore 23-Aug-12 5:33am    
Added code block

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...
 
Share this answer
 
If you wish to save the troubles Griff mentioned above, then you can try with this Word .NET[^] component. It solves your every trouble.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900