How to upload and download Media to or from MSSQL Server Database

This code shows you how to upload media files to the SQL Server Database to store it and then how to download it from the Database in your ASP.NET website using C#.

First you have to create a database named “MediaDB” in your SQL Server. Then create a table named “MediaTable” in your newly created database. Now create 4 columns in “MediaTable” as given below-

  1. ID (int, not null, IsIndentity: Yes)
  2. FileName (text, allow nulls)
  3. MediaData (varbinary(MAX), allow nulls)
  4. Extension (text, allow nulls)

Then save all.
Now create a new Visual C# type website in your Visual Studio.

Here is the code of your website’s “Default.aspx” page code:

And here is the code of your website’s “Default.aspx.cs” page code:

Tagged , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *