I am trying to open a Word document from a .Net web application. The code (in brief) contains ...
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;
and, the code that actually creates the document includes:
object oMissing = System.Reflection.Missing.Value;
object oEndOfDoc = "\\endofdoc"; // \endofdoc is a predefined bookmark
object oTemplate = WebConfigurationManager.AppSettings["GuidelineRepsTemplate"]; //this points to a .doc I am using as a template
//Start Word and create a new document.
Word._Application oWord;
Word._Document oDoc;
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add(ref oTemplate, ref oMissing, ref oMissing, ref oMissing);
object oBookMark = "Representative";
oDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = lblRecipient.Text;
object oBookMark1 = "Guidelines";
oDoc.Bookmarks.get_Item(ref oBookMark1).Range.Text = Guidelines.ToString();
object fileName = WebConfigurationManager.AppSettings["GuidelineRepsPath"] + ContactID.ToString() + "\\" + fileString2 + ".doc";
object FileFormat = Word.WdSaveFormat.wdFormatDocument;
oDoc.SaveAs(ref fileName, ref FileFormat, 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);
The Word document I use as a template has two bookmarks in it and I populate these bookmarks within the code above.
On my development box it all works fine. The document opens in Word, users can make changes if they wish and it saves in the directory I have created for it (directory code not shown above).
When I publish to a test server - every time I run it I get this error:
The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
The stack trace can't make it's mind up what is wrong - one example is:
[COMException (0x8001010a): The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))]
Microsoft.Office.Interop.Word.DocumentClass.get_Bookmarks() +0
SendConfirmEmailReps.CreateDocs(Int32 ContactID, Int32 OrganisationID) +942
SendConfirmEmailReps.Page_Load(Object sender, EventArgs e) +317
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +50
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
which suggests something wrong with the bookmarks. So I took references to the bookmarks out and started using a file called Hello.doc as my template. No bookmarks - just the word 'hello' in it.
This fell over too - but the StackTrace indicated it was when SaveAs was called.
So, the question is ... why does it work on my development box but not on the server. The server has Word installed on it.
Thanks for any help.