Last post Feb 23, 2011 02:45 AM by rogerz1234567
Feb 21, 2011 02:18 AM|rogerz1234567|LINK
I have to Create a Word File in a specific folder. So, we are using Word Automation. When i am running the code on my local machine(From VS) everything works fine and the word document is created. But when i host it on IIS it starts giving exception.
[COMException (0x800a1098): This command is not available because no document is open.] Microsoft.Office.Interop.Word.ApplicationClass.get_ActiveWindow() +0 Admin_TestPage.Button1_Click(Object sender, EventArgs e) +430 System.Web.UI.WebControls.Button.OnClick(EventArgs
e) +118 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
protected void Button1_Click(object sender, EventArgs e)
ClsBrowse oBrowse = new ClsBrowse();
DataTable dt = new DataTable();
int pvntPageCount = 0;
int pvntErrorNo = 0;
string pvntErrorDescription = string.Empty;
string emptyStr = "";
clsBatchProcess clsbp = new clsBatchProcess();
string lstrPath = @"Emails\Docs\";
modDBConnection objDBCon = new modDBConnection();
//objDBCon.gfblnReadINIFile(modDBConnection.mstr_APP_NAME, "EmailDocs", ref lstrPath);
//string path = "~/" + lstrPath;
DirectoryInfo dirnfo = new DirectoryInfo(System.Web.HttpContext.Current.Server.MapPath(@"Emails\Docs\"));
FileStream MyFile = File.Create(dirnfo.FullName + "Test.txt");
StreamWriter test = new StreamWriter(dirnfo.FullName + "Test.txt");
oWord = new Word.Application();
oWord.Visible = true;
oDoc = oWord.Documents.Add();
oWord.ActiveWindow.View.TableGridlines = false;
oPara1 = oDoc.Content.Paragraphs.Add();
oDoc.SaveAs(System.Web.HttpContext.Current.Server.MapPath(lstrPath) + "TestWord" + ".doc");
oWord = null;
This is a test code that i wrote to just check where is the problem. The text file is being created everytime (both when i run from VS and from IIS). But the word file through exception on IIS.
Kindly, help me. I have been facing this problem for 2 days and google was also not helpful.
Feb 21, 2011 03:31 AM|krisrajz|LINK
You are using office automation at client computer which requires MS Office to be installed.
The same might not be possible in a server side environment and microsoft does not recommend to use MS Office COM automation in a server side environment.
Just search, CodePlex.com
Feb 21, 2011 11:32 PM|rogerz1234567|LINK
Actually we are migrating an application from ASP to ASP.Net. We will have Office installed on all the clients PC's. Office is also installed on the server. I know that Office automation this way is not recommended but i have done it now and just need a
solution to this problem :(.
Thank your for your reply.
Feb 23, 2011 02:45 AM|rogerz1234567|LINK
Someone posted this.
I know this question is a bit old already but since we recently had the same issue, I thought I'd share how we solved it.
On the server log in as administrator and make sure to open Word a couple of times so that it won't pop up with any dialogs on startup.
In the Tree on the left go to
Component Services -- Computers -- My Computer -- DCOM Config
Under the list of programs right click on
Microsoft Office Word ... Choose Properties.
On Identity Tab Click
and enter the credentials of the admin account.
I'm not quite sure if this is needed, but we also set permissions for the app pool's account to the three options on the security tab.