This is a migrated thread and some comments may be shown as answers.

Accessing Binary Content of Inserted or Updated Data in GridBinaryImageColumn

2 Answers 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Richard Weeks
Top achievements
Rank 2
Richard Weeks asked on 19 Apr 2012, 02:07 AM
The subject says it all :) I have a GridBinaryImageColumn in a RadGrid as:
<telerik:GridBinaryImageColumn
    DataAlternateTextField="Title"
    DataField="BinaryContent"
    HeaderText="Image"
    ImageAlign="NotSet"
    ImageHeight="120px"
    ImageWidth="120px"
    ResizeMode="Fit"
    UniqueName="BinaryContent">
</telerik:GridBinaryImageColumn>

I'm using code-behind and Entity Framework and want to take the binary content of the selected file and set that to the appropriate entity property (which is of course byte[]).

How? All the samples I can find are declarative or not quite what I want. Here's an example of where I'd like to place such functionality:

protected void SetValues(GridCommandEventArgs e)
{
    if (e == null)
    {
        return;
    }
 
    if (!(e.Item is GridEditableItem))
    {
        return;
    }
 
    var editedItem = e.Item as GridEditableItem;
 
    var hashTable = new Hashtable();
 
    e.Item.OwnerTableView.ExtractValuesFromItem(hashTable, editedItem);
 
    // Simpler form of access naturally won't work.
    if (hashTable.ContainsKey("BinaryContent"))
    {
        // I KNOW I can't access the content like this:
        //  this.EntityBinaryContent = hashTable["BinaryContent"] == null
        //     ? null
        //     : SomeUtility.ConvertToBytes(hashTable["BinaryContent"]);
 
        // But at this stage, with what I have to work with (e) etc.
        // How can I easily get hold of the upload bytes?
    }
}

Edit: Should mention the intention is that the binary data goes into the database and the file is never saved to a file system. So, I can't work with an uploaded file as there won't be one.

Many thanks,
Richard

2 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 24 Apr 2012, 07:11 AM
Hello Richard,

You cannot get the binary content from RadBinaryImage once it is bound. After binding, the the value is deleted and there is no way how you can retrieve it. You will need to get it from data base in order to use it for other purposes.

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Richard Weeks
Top achievements
Rank 2
answered on 24 Apr 2012, 07:28 AM
Thank you for your response. That makes sense.

I managed to get access to the binary contents by reading the relevant RadUpload uploaded files inputstream.

Richard

Tags
Grid
Asked by
Richard Weeks
Top achievements
Rank 2
Answers by
Tsvetina
Telerik team
Richard Weeks
Top achievements
Rank 2
Share this question
or