SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a webpart which shows document data from a webservice. I can use the same webservice to get a byte[] which contains data for a thumbnail image of the document.

the image should be shown in a spgridview which uses a ObjectDataSource. All of this happens in the same webpart. If i am not mistaken a System.Web.UI.WebControls.Image object should be used to show the image in a sharepoint webpart. If this is correct the question is: How do i translate the byte array to a System.Web.UI.WebControls.Image?

share|improve this question
up vote 0 down vote accepted

I solved after some research. Here is my solution.

Since my bytearray is received from a webservice and it does not have a physical location on the server i created one.

private string ByteArrayToFile(string filename, byte[] bytearray)
    //set filelocation.
    string filelocation = @"C:\TempFile\ " + filename;

    //Open file for reading
    System.IO.FileStream fs = new FileStream(filelocation, FileMode.Create, FileAccess.Write);

    //Writes a block of bytes to this stream using data from the bytearray.
    fs.Write(bytearray, 0, bytearray.length);

    //Close file stream.

    //returns filelocation.
    return filelocation;

At this point we have the file on a physical point on the server. To use the image and show it in a datagrid i used the following link:

share|improve this answer

Your Answer


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.