Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top