Answered by:
Word File Creation Error

Question
-
User82239924 posted
Dear All,
I am working on asp.net 3.5.
In my application, i am creating a word file using the below code.
object nullobj = System.Reflection.Missing.Value; object oMissing = System.Reflection.Missing.Value; object oEndOfDoc = "\\endofdoc"; /* \endofdoc is a predefined bookmark */ //Start Word and create a new document. Microsoft.Office.Interop.Word._Application oWord; Microsoft.Office.Interop.Word._Document oDoc; oWord = new Microsoft.Office.Interop.Word.Application(); oWord.Visible = true; oDoc = oWord.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); //Insert a paragraph at the beginning of the document. Microsoft.Office.Interop.Word.Paragraph oPara1; oPara1 = oDoc.Content.Paragraphs.Add(ref oMissing); foreach (RepeaterItem ri in Repeater1.Items) { Label lbl = (Label)ri.FindControl("ltrlForm"); Literal ltr = (Literal)ri.FindControl("ltrlComment"); string tst = StripHtml(ltr.Text, false); string tst1 = Server.HtmlEncode(ltr.Text.ToString()); string newstr = ltr.Text.Replace("<BR>", "~"); string[] htmlstr = newstr.Split('~'); oPara1.Range.Text = lbl.Text; oPara1.Range.Font.Bold = 1; oPara1.Range.Font.Size = 14; oPara1.Range.Font.Name = "Cambria"; oPara1.Format.SpaceAfter = 6; //24 pt spacing after paragraph. oPara1.Range.InsertParagraphAfter(); Microsoft.Office.Interop.Word.Paragraph oPara2; object oRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range; oPara2 = oDoc.Content.Paragraphs.Add(ref oRng); oPara2.Range.Font.Size = 10; oPara2.Range.Font.Bold = 0; oPara2.Range.Font.Name = "Verdana"; if (htmlstr.Length > 1) { for (int i = 0; i < htmlstr.Length; i++) { oPara2.Range.Text = StripHtml(htmlstr[i].ToString(), false); oPara2.Range.InsertParagraphAfter(); oPara2.Range.Font.Name = "Verdana"; oPara2.Range.Font.Size = 10; oPara2.Range.Font.Bold = 0; } } else { oPara2.Range.Text = tst.ToString(); oPara2.Range.InsertParagraphAfter(); oPara2.Range.Font.Name = "Verdana"; oPara2.Range.Font.Size = 10; oPara2.Range.Font.Bold = 0; } oPara2.Range.Font.Bold = 0; oPara2.Range.Font.Size = 10; oPara2.Format.SpaceAfter = 30; }
When I run the application from the VS, its working fine and word file is generating.
When I host the site in my Local IIS, its not working. I am getting error message.
The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))
Can anyone help me.
Thanks in advance.
Friday, July 8, 2011 8:49 AM
Answers
-
User-1659704165 posted
Hi,
If you are Work With Word Application or Office Application
Better use OpenXml for That Rather Then usimng Word Interop.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, July 9, 2011 11:21 AM -
User82239924 posted
As it was too late to complete my project, I tried out alternate for the solution.
Anyway thanks for the replies.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 12, 2011 7:33 AM -
User82239924 posted
I used the below code.
StringBuilder strBuilder = new StringBuilder(); strBuilder.Append("<h2 title='Header' align='Center'>SMS Forms Review</h2> ".ToString()); strBuilder.Append("<br>".ToString()); strBuilder.Append("<table align='Left'>".ToString()); strBuilder.Append("<tr>".ToString()); strBuilder.Append("<td style='width:100px;color:Black;'><b>Vessel :</b></td>".ToString()); strBuilder.Append("<td style='width:500px;color:red;'" + Session["shipName"].ToString() + " </td>".ToString()); strBuilder.Append("</tr>".ToString()); strBuilder.Append("<tr>".ToString()); strBuilder.Append("<td style='width:100px;color:Black;'><b>Date :</b></td>".ToString()); strBuilder.Append("<td style='width:500px;color:Black;'>" + DateTime.Now.ToShortDateString() + "</td>".ToString()); strBuilder.Append("</tr>".ToString()); strBuilder.Append("</table>".ToString()); strBuilder.Append("<br/><br/>".ToString()); foreach (RepeaterItem ri in Repeater1.Items) { Label lbl = (Label)ri.FindControl("ltrlForm"); Literal ltr = (Literal)ri.FindControl("ltrlComment"); string tst = StripHtml(ltr.Text, false); string tst1 = Server.HtmlEncode(ltr.Text.ToString()); string newstr = ltr.Text.Replace("<BR>", "~"); string[] htmlstr = newstr.Split('~'); strBuilder.Append("<div style='font-family:Cambria; font-size:Meduim; color:Black; font-weight:Bold;'>"); strBuilder.Append(lbl.Text); strBuilder.Append("</div><br />"); strBuilder.Append(ltr.Text); strBuilder.Append("<br />"); strBuilder.Append("<br />"); } string strPath = Request.PhysicalApplicationPath + "\\Documents\\Mail_Compilation_" + Session["UserName"].ToString() + ".doc"; FileStream fStream = File.Create(strPath); //fStream.Flush(); fStream.Close(); StreamWriter sWriter = new StreamWriter(strPath); sWriter.Write(strBuilder); sWriter.Close(); Response.Redirect("~/Documents/Mail_Compilation_" + Session["UserName"].ToString() + ".doc");
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 12, 2011 7:33 AM
All replies
-
User-1659704165 posted
Hi,
If you are Work With Word Application or Office Application
Better use OpenXml for That Rather Then usimng Word Interop.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, July 9, 2011 11:21 AM -
User82239924 posted
As it was too late to complete my project, I tried out alternate for the solution.
Anyway thanks for the replies.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 12, 2011 7:33 AM -
User82239924 posted
I used the below code.
StringBuilder strBuilder = new StringBuilder(); strBuilder.Append("<h2 title='Header' align='Center'>SMS Forms Review</h2> ".ToString()); strBuilder.Append("<br>".ToString()); strBuilder.Append("<table align='Left'>".ToString()); strBuilder.Append("<tr>".ToString()); strBuilder.Append("<td style='width:100px;color:Black;'><b>Vessel :</b></td>".ToString()); strBuilder.Append("<td style='width:500px;color:red;'" + Session["shipName"].ToString() + " </td>".ToString()); strBuilder.Append("</tr>".ToString()); strBuilder.Append("<tr>".ToString()); strBuilder.Append("<td style='width:100px;color:Black;'><b>Date :</b></td>".ToString()); strBuilder.Append("<td style='width:500px;color:Black;'>" + DateTime.Now.ToShortDateString() + "</td>".ToString()); strBuilder.Append("</tr>".ToString()); strBuilder.Append("</table>".ToString()); strBuilder.Append("<br/><br/>".ToString()); foreach (RepeaterItem ri in Repeater1.Items) { Label lbl = (Label)ri.FindControl("ltrlForm"); Literal ltr = (Literal)ri.FindControl("ltrlComment"); string tst = StripHtml(ltr.Text, false); string tst1 = Server.HtmlEncode(ltr.Text.ToString()); string newstr = ltr.Text.Replace("<BR>", "~"); string[] htmlstr = newstr.Split('~'); strBuilder.Append("<div style='font-family:Cambria; font-size:Meduim; color:Black; font-weight:Bold;'>"); strBuilder.Append(lbl.Text); strBuilder.Append("</div><br />"); strBuilder.Append(ltr.Text); strBuilder.Append("<br />"); strBuilder.Append("<br />"); } string strPath = Request.PhysicalApplicationPath + "\\Documents\\Mail_Compilation_" + Session["UserName"].ToString() + ".doc"; FileStream fStream = File.Create(strPath); //fStream.Flush(); fStream.Close(); StreamWriter sWriter = new StreamWriter(strPath); sWriter.Write(strBuilder); sWriter.Close(); Response.Redirect("~/Documents/Mail_Compilation_" + Session["UserName"].ToString() + ".doc");
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, July 12, 2011 7:33 AM