0

C#では、csvファイルの印刷に問題があります

今のところ、エラーをスローしているだけで、ファイルは印刷されません

エラーは次のとおりです。

Sys.WebForms.PageRequestManagerParserErrorException:サーバーから受信したメッセージを解析できませんでした。

これが私の背後にあるコードです、助けてくれてありがとう、私はそれを正しくやっていると思います

    protected void csvbutton_Click(object sender, EventArgs e)
    {
        string filename = App_Name_L.ToString();

        StringBuilder sb = new StringBuilder();

        string[] columnNames = new string[]
        {
            "APPLICATION NAME",
            "DESCRIPTION",
            "APPLICATION OWNER",
            "TSO",
            "RESPONSIBLE MANAGER",
            "SIGN OFF",
            "CO-EXISTENCE STATUS",
            "CO-EXISTENCE PROGRESS",
            "MIGRATION PHASE",
            "NEXT STEPS",
            "LAST UPDATE"
        };
        sb.AppendLine(string.Join(",", columnNames));
        sb.AppendLine(Environment.NewLine);

        string[] fields = new string[]
        {
            App_Name_L.Text.ToString(),
            Description_L.Text.ToString(),
            App_Owner_L.Text.ToString().Replace(",", "."),
            TSO_L.Text.ToString().Replace(",", "."),
            Responsible_Manager_L.Text.ToString().Replace(",", "."),
            Sign_Off_L.Text.ToString().Replace(",", "."),
            this.status_export(0, Convert.ToInt16(CS_H.Value.ToString())),
            this.status_export(1, Convert.ToInt16(CP_H.Value.ToString())),
            Migration_Phase_L.Text.ToString(),
            Next_Steps_L.Text.ToString().Replace(",", "."),
            Last_Update_L.Text.ToString()
        };
        sb.AppendLine(string.Join(",", fields));

        stringout.Text = sb.ToString();

        Response.Clear();
        Response.ContentType = "text/csv";
        Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + ".csv\"");
        Response.Write(sb.ToString());
        Response.End();
    }
4

1 に答える 1

0

Joelこれは私がテストしたばかりのものであり、私の環境で機能します。これを見て、コードに適用できるかどうかを確認し、私が持っている場所をあなたのコードに置き換えdataてください。sb.Tostring();

private static void ExportToExcel(string data)
{
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=\"" + filename + ".csv\"");
    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
    HttpContext.Current.Response.ContentType = "text/csv";
    HttpContext.Current.Response.Write(data);
    HttpContext.Current.Response.End();
}
于 2013-02-04T18:11:05.343 に答える