打印Web表单时出错 [英] Error in printing web form

查看:85
本文介绍了打印Web表单时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



以下是我打印Webform的代码
我收到错误消息,因为

错误5"System.IO.StreamWriter"不包含在第3行中接受"0"参数的构造函数


请纠正我我要去哪里哪里


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

推荐答案

假设使用StringWriter错误地使用了StreamWriter
suppose to use StringWriter wrongly used StreamWriter


这篇关于打印Web表单时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆