tags:

views:

71

answers:

4

I have a question regarding how to retrieve an mp3 file stored as a byte[] array from the database and display it in a form and let the user to download/play it?

+5  A: 

Hmm. This sure can be done but if it is a RDBMS you realy should reconsider the solution. Usualy the database is not designed or optimized for using large binary objects and reading and writing the data is far from beeing optimal.

Why not storing the file in a folder and save the file- and folder-name to the database?

Yves M.
Agreed, large binary objects have no place in a database.
DavidGouge
If it's SQL Server version >2008 you can take advantage of the filestream type.
Carles
@Carles: true but still not an optimal version. Storing the files in a filesystem has also the advantage, that you can use indexing on the mp3 tags to let the user search for it.
Yves M.
A: 

Try using an HttpHandler. Here is a nice tutorial on creating one. You would simply write the byte array to the response stream and post a link in your application similar to this one.

http://myserver/myhttphandler.ashx?mp3File=x
Steve Danner
Could use a simple code sample, otherwise answer is a good one.
Russ
That's the easy part. The difficult part is getting it to stream in the browser. Images are a different story.
Josh Stodola
+1  A: 

To save the array of bytes as a file that can be downloaded, you can use a FileStream.

byte[] array; //Loaded array of bytes.
using (FileStream fs = new FileStream(path))
{
    fs.Write(array, 0, array.length);
}
Russ
but where should i show the link and how should i show it using a data grid or anything else??? i don't know how to do at all..
Leema