Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all

i have an .aspx page. now on page load i have to convert html part of that page in to .pdf format . for that i have to store whole html page in to a string so that i pass that string to my pdf converter function. this html page contain gridview and other data except images .now i didnt understand how to store html part of .aspx page in to a string .

plz help me

its urgent
thanxz in advance
Posted

Hi,
you can use the following method. This will work for all aspx pages(which includes any asp.net controls)
C#
private string GetHTMLContent()
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter w = new HtmlTextWriter(sw);
            //divHTMLWrapper is a div, which we set to runat 'server' and in this DIV the whole controls include
            divHTMLWrapper.RenderControl(w);
            string htmlString = sw.GetStringBuilder().ToString();
        }


// You must declare this function in the code file
C#
public override void VerifyRenderingInServerForm(Control control)
    {
    }


The aspx page will look like this. Your aspx controls should be in "divHTMLWrapper"
XML
<form id="form1" runat="server">
<pre lang="xml">
    <div id="divHTMLWrapper" runat="server">
    <div  style="width: 100%; background-position: center center;">
    <div style="margin:auto; width:280px">
    <img runat="server" src="images/logo_new.jpg" style="text-align:center" /></div>
    </div>
</div
</form>
 
Share this answer
 
Hi,

That isn't hard to do. All you need to do is using stream reader or any file reading mechanism, open the aspx file, read it into a string variable and pass it wherever you want.

Code sample is as below:

StreamReader sr = new StreamReader("FILE PATH");
string strText = sr.ReadToEnd();
sr.Close();
 
Share this answer
 
Comments
sharmarun 7-Dec-10 1:25am    
i have to read dynamically

what is this FILE PATH

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900