Click here to Skip to main content
15,902,887 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

below is my code to print webform
I am getting a error as

Error 5 'System.IO.StreamWriter' does not contain a constructor that takes '0' arguments in line 3


Please correct me where i am going wrong


public static void PrintWebControl(Control ctrl, string Script)
    {
        StreamWriter stringwriter = new StreamWriter();
        System.Web.UI.HtmlTextWriter htmlwriter = new System.Web.UI.HtmlTextWriter(stringwriter);
        if (ctrl is WebControl)
        {
            Unit w = new Unit(100, UnitType.Percentage); ((WebControl)ctrl).Width = w;

        }
        Page pg = new Page();
        pg.EnableEventValidation = false;
        if (Script != string.Empty)
        {
            pg.ClientScript.RegisterStartupScript(pg.GetType(), "PrintJavaScript", Script);
        }
        HtmlForm frm = new HtmlForm();
        pg.Controls.Add(frm);
        frm.Attributes.Add("runat", "server");
        frm.Controls.Add(ctrl);
        pg.DesignerInitialize();
        pg.RenderControl(htmlwriter);
        string strHTML = stringwriter.ToString();
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.Write(strHTML);
        HttpContext.Current.Response.Write("<script>window.print();</script>");
        HttpContext.Current.Response.End();


    }


Thanks
Posted

1 solution

suppose to use StringWriter wrongly used StreamWriter
 
Share this answer
 

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