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

I am trying to generate and download the .xls file that should include the image. I am able to generate and download the file and all the text is proper but Image is not appearing.
I am using the image url from web this is for example only.
Below is my code. Please guide me to know where I am lacking or putting wrong.

C#
System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("http://www.floristdex.com/images/flowers/alstroemeria.jpg");
            System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
            Stream stream = res.GetResponseStream();
            byte[] buffer = new byte[16*1024];
            using (var streamReader = new MemoryStream())
            {
                stream.CopyTo(streamReader);
                buffer = streamReader.ToArray();
            }

            MemoryStream mss = new MemoryStream(buffer);
            System.Drawing.Image mgg = System.Drawing.Image.FromStream(mss);

            System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
            strBuilder.Append(@"<table id=""exportToExcel"" runat=""server"" style=""width:100%;""><tr><td>");
            //strBuilder.Append(@"<img id=""Image1"" src=""http://www.floristdex.com/images/flowers/alstroemeria.jpg""  runat=""server""/>");
            strBuilder.Append(mgg);
            strBuilder.Append(@"</td><td>Hello</td></tr><tr><td>hi</td><td>Hello</td></tr></table>");

            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition","attachment; filename=ExcelFile.xls");
            Response.ContentType = "application/vnd.ms-excel";
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.Write(strBuilder);
            Response.End();



Thanks :)
Posted
Updated 17-Jul-14 4:21am
v2

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