using System;
using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Web.DynamicData;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Telerik.Web.UI.DynamicData;
using Telerik.Web.UI;
using System.IO;

public partial class BinaryImage_EditField : System.Web.DynamicData.FieldTemplateUserControl
{
    protected override void OnDataBinding(EventArgs e)
    {
        base.OnDataBinding(e);
    }

    protected override void ExtractValues(IOrderedDictionary dictionary)
    {
        if (RadUpload1.UploadedFiles.Count > 0)
        {
            UploadedFile file = RadUpload1.UploadedFiles[0];
            using (Stream stream = file.InputStream)
            {
                byte[] bytes = new byte[stream.Length];
                stream.Read(bytes, 0, (int)stream.Length);
                dictionary[Column.Name] = new System.Data.Linq.Binary(bytes);
            }            
        }
    }

    public override Control DataControl
    {
        get
        {            
            return RadUpload1;
        }
    }
}
