开发者

LINQ : saving files to a database

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 startin开发者_JAVA百科g out with LINQ and don't master it yet.


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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜