I am a beginner in .net Technology. I am using VS2008, C# ,Asp.Net 3.5 Framework, SQL SERVER 2005. In a database table 'Cust_M_Tbl', there is a field of varchar(500) type viz Cust_Image. The value in the Cust_Image is

mspZVnmQlz1GgRRpQEqBFGTHeUELiUhxQQ2GQU9BF3DCUYEeaiJJAQQLKGCBDYcySMENDi9qgQWJv0xBEe8sWkEEDr19QQWMxVoBE20odAEGFDtZAQeBtUtBDn7NUkEd0ytIAQl/r4WBBooWTAEHiCSGAQiMyjEBCFG+KYELYSoowQzluisBBt1NTwEYSM4hgQ5LTTpBD0e5KUEGYa0ugQxqoCLBCWgZKcEKcJJZQQ2DM1nBBAszVoEHiQMSZGhtcwEGCgwPExQUExMUFAMSYmVqcHUECQsOEBMTEhITFAISZWVobnUDCA0PERMVFRQUFRUDEWBjaG5yAQYLDg8REREREQISamlqb3UFCQ0PEhMUFRUWFhYDEV9hZmxxdQMJDQ4PEBEREQIRa2xucXcGCg0PEhMVFhgZGQQRY2ZpbXIBBgsNDxASExQDEHJzdgMHDA0PEBMVFxgZBBFiY2ZpbnMDCQsNDxIVFwMPc3YDBgkNDQ4PExQWGAQRXl9hY2ZqcwQIDBATFxgEDgQHCgwPDQ8PEhMVAxFXWFlcXV9hbXYFCxIWGRoGDA0ODwsODxMDEFVXV1dVVltkcwYOFhodAAD/Aw1PUVFQTk5RV2YKEQAA/wQMR0VFR0ZJQz0xAAD/BQdCQkMY8B0ZtKlQFCF/MssEMp7YkXe5scQP8fmd96ZVrvO8oGFXhoDAjEe5o+U/XAnxKOTp9vDgoSTOH22Eg2rytkcs9uqvFV7GSeUaetGWD0jVWeSqCuD6Sb6l/KxsWXbH1iDoY8LJhgKhkvVBei3Xmp4gx74bl58QiXckdX0KgxJhDWSa/zDvZvGfSVKVLvXzhv8/A+3tV1M36hSdkpPukozfqJj4O9ELUHNNUj8SRvFr0do7bU6tXqEbVubYYiVnalpHbCb07QoVPsO402Lwu3d9vnk6+bnZ/zbgpmAm4zfCLQrlOseeQ4XOarfqeCA14qS2EWZxATfilss++PYY+xymdxgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGBgYGA==

I want to display this customer image in my web page. How can I do it? Should I decrypt it? or it is in any other format? Any help will be appreciated. Regards,

share|improve this question
What have you tried? By the way you shouldn't post customers image source it can hold personal information. – Reniuz Dec 12 '11 at 7:44
@Reniuz....its an edited one just used for example – sun Dec 12 '11 at 7:48
feedback

2 Answers

up vote 0 down vote accepted

After decoding as @Christophe Geers suggested use

string encodedString = "your image data encoded as base 64 char array";
byte[] data = Convert.FromBase64String(encodedString);

Response.BinaryWrite(data);

maybe this can help more: http://odetocode.com/articles/172.aspx

share|improve this answer
feedback

This looks like Base64 encoding. You can find an online decoder here:

http://en.wikipedia.org/wiki/Base64

It validates your input as a valid Base-64 char array.

You can decode a base64 string in C# in the following way:

string encodedString = "your image data encoded as base 64 char array";
byte[] data = Convert.FromBase64String(encodedString);

Take a look at the FromBase64String article on MSDN for more information.

Now you want to display the image on an ASP.NET web page (*.ASPX).

E.g.:

<img src="myimage.jpg" />

Instead of referencing an actual image file (eg: myimage.jpg), you want to reference an ASP.NET handler (*.ASHX) that serves the bytes of the image (the byte[] array named data in the previous code sample).

E.g.:

<img src="ImageHandler.ashx" />

The code for the image handler looks something like this:

public class ImageHandler : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        // Load the image (see previous code sample)
        byte[] data = ...;

        // Display the image
        context.Response.OutputStream.Write(data, 0, data.Length);
        context.Response.ContentType = "image/JPEG";
    }
}

Read more about implementing an IHttpHandler on MSDN.

You need to pass an identifier to the imagehandler.ashx page so that you know which image to retrieved.

E.g.:

<img src="ImageHandler.ashx?id=<%=id%>" />

Put this instead of your img-tag or your ASP.NET image control.

share|improve this answer
though it is a first step it does not really explain how to display the image – Rune FS Dec 12 '11 at 7:52
@Christophe Geers....I got this error- Error 2 The name 'Encoding' does not exist in the current context. How can I load this data to my img control? – sun Dec 12 '11 at 7:59
Are you sure that you really need to hold the byte[] in a string ? why ? – A.B.Cade Dec 12 '11 at 8:04
@A.B.Cade...I am not so particular of that...i just need to display the image As Cristophe suggested I used the following code- string encodedString = c.dr.GetValue(0).ToString(); byte[] data = Convert.FromBase64String(encodedString); string decodedString = Encoding.UTF8.GetString(data); – sun Dec 12 '11 at 8:07
@Christophe Geers....I got the decodedString.Thanks Cristophe....But how can I connect it with my image control – sun Dec 12 '11 at 8:12
show 5 more comments
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.