Decoding multiple Base64 strings and displaying the images in web application?http://forums.asp.net/t/1777834.aspx/1?Decoding+multiple+Base64+strings+and+displaying+the+images+in+web+application+Wed, 07 Mar 2012 19:34:43 -050017778344868864http://forums.asp.net/p/1777834/4868864.aspx/1?Decoding+multiple+Base64+strings+and+displaying+the+images+in+web+application+Decoding multiple Base64 strings and displaying the images in web application? <p>(Please let me know if this doesn't belong in the right forum, I'm still a little new to the site)</p> <p></p> <p>I'm currently working on building an application that queries the database and returns 1 or more rows of data which each row contains a column designating an encoded string. This is what I do after running this query:</p> <p></p> <p><strong>foreach (DataRow dtrData in datatableImage.Rows)</strong><br> <strong>{</strong></p> <p><strong>&nbsp;&nbsp; string strHEX = dtrData[&quot;encodedImageHEX&quot;].ToString();</strong><br> <strong>&nbsp;&nbsp; Base64ToImage(strHEX);</strong></p> <p><strong>}</strong></p> <p></p> <p><strong>private void Base64ToImage(string strHEX)</strong></p> <p><strong>{</strong></p> <p><strong>&nbsp;&nbsp; byte[] imageBytes = Convert.FromBase64String(strHEX);</strong><br> <strong>&nbsp;&nbsp; MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);</strong><br> <strong>&nbsp;&nbsp; ms.Write(imageBytes, 0, imageBytes.Length);</strong><br> <strong>&nbsp;&nbsp; Image image = Image.FromStream(ms, true);</strong><br> <strong>&nbsp;&nbsp; Response.ContentType = &quot;image/jpeg&quot;;</strong><br> <strong>&nbsp;&nbsp; ms.WriteTo(Context.Response.OutputStream);</strong></p> <p><strong>}</strong></p> <p></p> <p>The problem is that when the query returns multiple rows, only the first image is decoded and displayed on the page. It seems to completely ignore my foreach loop. Is there a way to output multiple decoded images to the page? My colleague mentioned about using sessions to store the decoded data and just spitting out html &lt;img&gt; tags to the page (I want to be able to just display them immediately on the page WITHOUT having to save the image first).</p> <p></p> <p>If anyone can provide me with some guidance on how I can achieve this I would greatly appreciate it! Thanks!</p> 2012-03-07T19:34:43-05:00