We help IT Professionals succeed at work.

Transferring text from ASP.NET web form to a Word doc without HTML tags

Vrik22
Vrik22 asked
on
75 Views
Last Modified: 2019-02-16
How to render only text into a word document using asp.net web forms ?

I am using the below code , but, it is rendering with <html> tags :

 
Response.Clear();
                Response.Buffer = true;
                Response.ContentType = "application/vnd.word";
                Response.ContentEncoding = System.Text.Encoding.UTF7;
                Response.AddHeader("Content-Disposition", "attachment;filename=xyz.doc");
                Response.Charset = "";
                EnableViewState = false;
                System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
                oStringWriter.Write(txtDetails.Text);
                System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
                PanelControlId.RenderControl(oHtmlTextWriter);
                Response.Write(oStringWriter.ToString());
                HttpContext.Current.ApplicationInstance.CompleteRequest();

Open in new window


I want only text to be rendered in word and not with html tags. Please help .
Comment
Watch Question

Citrix Technology Professional / Director of TechDev Services, IPM
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION