like below data in ms word document
<div id="ctl00_ContentPlaceHolder1_design" style="width:600px">
<table id="ctl00_ContentPlaceHolder1_rpt" border="0" width="600">
how to convert html tags to plain content ?
aspx.cs
protected void btnMail_Click(object sender, EventArgs e)
{
Response.Clear();
try
{
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
design.RenderControl(htmlWrite);
string strBuilder = stringWrite.ToString();
string strPath = Request.PhysicalApplicationPath + "\\Temp\\WeeklyReport of " + Projname + ".doc";
if (File.Exists(strPath))
{
var counter = 1;
strPath = strPath.Replace(".doc", " (" + counter + ").doc");
while (File.Exists(strPath))
{
strPath = strPath.Replace("(" + counter + ").doc", "(" + (counter + 1) + ").doc");
counter++;
}
}
var doc = DocX.Create(strPath,DocumentTypes.Document);
doc.InsertParagraph(strBuilder);
doc.Save();
}
}
If it is all the text inside the div you want, then you could do this.
ASP.NET
<div runat="server" id="design" style="width:600px">
SOME TEXT <span> text </span>
</div>
C#:
string allTextInsideDiv = design.InnerText; //You should get "SOME TEXT text"
Edited: In further to our discussion you could not get InnerText as you have some ASP.NET server controls inside the div. So the solution would be to get the HTML code and using an XmlDocument or HtmlDocument object, load the content into it. Then extract the InnerText out.
Sample code:
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
div_myDiv.RenderControl(htmlWrite);
string myText = stringWrite.ToString().Replace("&", "&");
XmlDocument xDoc = new XmlDocument();
xDoc.LoadXml(myText);
string rawText = xDoc.InnerText;