Where and how I have to keep binary data of each file, because I need them after for saving in a database
<p>In my page I have 2 buttons one button for upload files and shows them in a grid view and another button "send" for saving files in a database.</p>

<p>I have used below code that shows file name, size and type in a grid view and then I can get these values from grid view and save in database. But I have problem for binary data.
I do not know where and how I have to keep binary data of each file, because I need them after for saving in a database.</p>

<pre><code>protected void btnUpload_Click(object sender, EventArgs e)
{
    DataTable dt;
    DataRow dr = null;
    bool isDuplicate = false;



    if (FileUpload1.HasFile)
    {
        FileInfo fileObj = new FileInfo(FileUpload1.PostedFile.FileName);
        string FileName = FileUpload1.PostedFile.FileName;


        long size = FileUpload1.PostedFile.ContentLength;

        string ext = Path.GetExtension(FileName);

        string contenttype = String.Empty;



        //Set the contenttype based on File Extension

        switch (ext)
        {

            case ".doc":

                contenttype = "application/vnd.ms-word";

                break;

            case ".docx":

                contenttype = "application/vnd.ms-word";

                break;

            case ".xls":

                contenttype = "application/vnd.ms-excel";

                break;

            case ".xlsx":

                contenttype = "application/vnd.ms-excel";

                break;

            case ".jpg":

                contenttype = "image/jpg";

                break;

            case ".png":

                contenttype = "image/png";

                break;

            case ".gif":

                contenttype = "image/gif";

                break;

            case ".pdf":

                contenttype = "application/pdf";

                break;

        }

        Stream fs = FileUpload1.PostedFile.InputStream;

        BinaryReader br = new BinaryReader(fs);

        Byte[] bytes = br.ReadBytes((Int32)fs.Length);


        if (FileUpload1.PostedFile.ContentLength &gt; 0)
        {


            if (GridViewEfile.Rows.Count &gt; 0)
            {

                int count = GridViewEfile.Rows.Count;

                dt = new DataTable();

                DataColumn dc1 = new DataColumn("File Name", typeof(string));

                DataColumn dc2 = new DataColumn("File Size", typeof(string));

                dt.Columns.Add(dc1);

                dt.Columns.Add(dc2);



                for (int i = 0; i &lt; count; i++)
                {
                    if (GridViewEfile.Rows[i].Cells[1].Text == FileName)
                    {
                        Label2.Text = "File already in the list";
                        isDuplicate = true;
                        break;
                    }
                }

                for (int j = 0; j &lt; count; j++)
                {
                    dr = dt.NewRow();
                    dr["File Name"] = GridViewEfile.Rows[j].Cells[1].Text;
                    dr["File Size"] = GridViewEfile.Rows[j].Cells[2].Text;
                    dt.Rows.Add(dr);
                }

                if (!isDuplicate)
                {
                    if (size == 0)
                    {
                        Label2.Text = "File size cannot be 0";
                    }
                    else
                    {
                        dr = dt.NewRow();
                        dr["File Name"] = FileName;
                        dr["File Size"] = size.ToString() + " KB";

                        dt.Rows.Add(dr);
                    }
                }

                GridViewEfile.DataSource = dt;
                GridViewEfile.DataBind();
                    }






            else
            {
                dt = new DataTable();

                DataColumn dc1 = new DataColumn("File Name", typeof(string));

                DataColumn dc2 = new DataColumn("File Size", typeof(string));

                DataColumn dc3 = new DataColumn("Content Type", typeof(string));

                DataColumn dc4 = new DataColumn("Bytes", typeof(Byte[]));

                dt.Columns.Add(dc1);

                dt.Columns.Add(dc2);
                dt.Columns.Add(dc3);
                dt.Columns.Add(dc4);

                dr = dt.NewRow();

                dr["File Name"] = FileName;

                if (size &gt; 0)
                    dr["File Size"] = size.ToString() + " KB";
                else
                { dr["File Size"] = fileObj.Length.ToString() + " Bytes"; }

                dr["Content Type"] = contenttype;
                dr["Bytes"] = bytes;
                var x = bytes;
                var y = dr["Bytes"];
                dt.Rows.Add(dr);
                GridViewEfile.DataSource = dt;
                GridViewEfile.DataBind();
            }

        }


    }
    else
    {
        Label2.Text = "Please select a file to add";
    }
}
</code></pre>
