Last post Jul 12, 2011 07:33 AM by prabinyovan
Participant
1292 Points
500 Posts
Jul 08, 2011 08:49 AM|prabinyovan|LINK
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.
Can anyone help me.
Thanks in advance.
All-Star
32861 Points
7877 Posts
Jul 09, 2011 11:21 AM|qwe123kids|LINK
Hi,
If you are Work With Word Application or Office Application
Better use OpenXml for That Rather Then usimng Word Interop.
Jul 12, 2011 07:33 AM|prabinyovan|LINK
As it was too late to complete my project, I tried out alternate for the solution.
Anyway thanks for the replies.
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");
Participant
1292 Points
500 Posts
Word File Creation Error
Jul 08, 2011 08:49 AM|prabinyovan|LINK
Dear All,
I am working on asp.net 3.5.
In my application, i am creating a word file using the below code.
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.
Nothing is really over,until the moment u stop trying for it....
All-Star
32861 Points
7877 Posts
Re: Word File Creation Error
Jul 09, 2011 11:21 AM|qwe123kids|LINK
Hi,
If you are Work With Word Application or Office Application
Better use OpenXml for That Rather Then usimng Word Interop.
Avinash Tiwari
Remember to click “Mark as Answer” on the post, if it helps you.
Participant
1292 Points
500 Posts
Re: Word File Creation Error
Jul 12, 2011 07:33 AM|prabinyovan|LINK
As it was too late to complete my project, I tried out alternate for the solution.
Anyway thanks for the replies.
Nothing is really over,until the moment u stop trying for it....
Participant
1292 Points
500 Posts
Re: Word File Creation Error
Jul 12, 2011 07:33 AM|prabinyovan|LINK
I used the below code.
Nothing is really over,until the moment u stop trying for it....