The subject says it all :) I have a GridBinaryImageColumn in a RadGrid as:
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:
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
<
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