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?


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:


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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