Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
154 views
Welcome To Ask or Share your Answers For Others

1 Answer

I used VSTO long time ago maybe 7 or 8 years ago but not in server side... And it was painful I suffered a lot with stuck processes, memory leaks and strange problems my code worked somewhere and somewhere else not (like yours). The solution was that OS language and installed Office language not matched. So you should check that and also check your code culture info:

Thread.CurrentThread.CurrentUICulture;
Thread.CurrentThread.CurrentCulture;

If you really need VSTO (I can`t see why??) check the languages, install Office Language Pack, so on... but I also recommend to use something else.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...