Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

1 Answer 1

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.
    fs.Close();

    //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:

http://replicrux.com/2011/05/15/adding-template-column-to-spgridview.aspx

share|improve this answer
add comment

Your Answer

 
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.