Tuesday, 19 September 2017

Asp.Net c# export Chart to Image

using System.IO;

protected void btnExport_Click(object sender, EventArgs e)
        {
            MemoryStream stream=new MemoryStream();           
            Chart1.SaveImage(stream, ChartImageFormat.Jpeg);
            BinaryReader binrayRdr = new BinaryReader(stream);
            byte[] bytes = ((MemoryStream)stream).ToArray();
            Response.Clear();
            Response.ContentType = "image/png";
            Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
            Response.Buffer = true;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.BinaryWrite(bytes);
            Response.End();
        }

No comments:

Post a Comment