Accessing Binary Content of Inserted or Updated Data in GridBinaryImageColumn

3 posts, 0 answers
  1. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 18 Apr 2012 Link to this post

    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. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 24 Apr 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Richard Weeks
    Richard Weeks avatar
    95 posts
    Member since:
    Oct 2009

    Posted 24 Apr 2012 Link to this post

    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

Back to Top