How to store binary files (BLOB) data using Entity Framework in C# .Net

Last Reply on Nov 11, 2013 08:47 AM By Mudassar

Posted on Nov 10, 2013 11:44 PM

Hi , I want to store binary files (blob)I searched many forums  but didn't found !
My question is : how to store binary file (Doc , Pdf , txt..) type blob into database using Entity framework(edmx) With ASP.NET c#
please help !

Posted on Nov 11, 2013 08:47 AM

This way

 

protected void UploadFile(object sender, EventArgs e)
    {
        using (FilesEntities entities = new FilesEntities())
        {
            tblFile file = new tblFile
            {
                Name = Path.GetFileName(fuUploadFile.PostedFile.FileName),
                ContentType = fuUploadFile.PostedFile.ContentType,
                Data = fuUploadFile.FileBytes,
            };
            entities.AddTotblFiles(file);
            entities.SaveChanges();
        }
    }