I am editing a word template and then saving it in on web server. for this i am using Interop.Word
(i know this is bad but still...)
I have installed MS Word on server
Here is My code:
object fileName;
object saveAs;
fileName = Server.MapPath("~\tempOutputs\Template - Filled with Registration Data.docx");
try
{
object missing = System.Reflection.Missing.Value;
Word.Application wordApp = new Word.Application();
Word.Document aDoc = null;
if (File.Exists((string)fileName))
{
object readOnly = false;
object isVisible = false;
wordApp.Visible = false;
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, ref missing, ref missing,
ref missing, ref missing);
aDoc.Activate(); //Error Line
I am getting error on aDoc.Activate()
statement as object reference not set to an instance
But it works on my system
Any suggestions ?
EDIT
I have wrote a console application using the code above and run it on server it runs perfectly then why not on IIS as web app ?
See Question&Answers more detail:os