views:

215

answers:

3

I want to save a pdf and mp3 file(s) to a SQL Server database and be able to retrieve from it. I'm still starting out with LINQ and don't master it yet.

A: 

You need to convert these into byte arrays (System.Data.Linq.Binary). One line to load

var myMp3 = new Binary(File.ReadAllBytes(mp3Filename));

If you create your database schema (VarBinary in the database) and drag the table over from Server Explorer into the DBML designer, it'll do everything for you.

Will
+1  A: 

To start off with your going to have a binary field in your database to save the file to.

Are you using LinqToSql, EntityToSql, or? Need some more information...

But once you get an object with a []byte to save the file to then it just a matter of making the appropriate Save() call... but with having some more information it hard to say.

Did you google tutorials?

Here is one that I found: Uploading Binary files or Images using LINQ to SQL

Has example code and sql to generate dummy tables...

J.13.L