Question : ASP .NET IIS 7 Word Interop Mail Merge (Interact With Desktop)

I am writing an ASP .NET application that users the Word Interop to do a mailmerge.  Works fine on my local dev environment.  But in II7 it can't open a document.  I think that's because IIS 7 can't interact with the Desktop (or log on locally), but I can't figure out how to get IIS and the ASP .NET user to be able to do that.  App crashes on the last line below, saying that there's no object reference.  So the "Open" method returned a null Word doc.  I've confirmed that I can access and open the file in question by using System.IO.File.Open().  I've also run the code from a thick client app locally and it works fine (when I'm logged in running it).  Thank you in advance for any help.

using Word = Microsoft.Office.Interop.Word;

Word.MailMerge wrdMailMerge;
        string originalFileName = System.IO.Path.GetFileNameWithoutExtension(documentPath);

        // Create an instance of Word
        wrdApp = new Word.Application();

        Word._Document oWordDoc;

        Object fileName = documentPath;
        oWordDoc = wrdApp.Documents.Open(ref fileName, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

        wrdMailMerge = oWordDoc.MailMerge;

Answer : ASP .NET IIS 7 Word Interop Mail Merge (Interact With Desktop)

Office applications are expected to run interactively, so there are a number of problems automating Office from IIS or from other non-interactive environments.  See this kb article for details and workarounds.

Considerations for server-side Automation of Office
http://support.microsoft.com/?kbid=257757

Mail merge can also be done more generically as HTML or RTF using simple string manipulation or with XSL transformations.  

http://msdn.microsoft.com/en-us/library/aa537151(office.11).aspx

Random Solutions  
 
programming4us programming4us