Background
You need to just find an answer for the ASP.NET, MVC is just a sub category of the ASP.NET web applications or web sites. ASP.NET is built directly oowrhe stuff that works with .NET Framework would work in ASP.NET too.
Finding the code
This project (problem) has been up for many developers, for using the SQL Server and storing images in it. There are many projects or articles for it. The basic implementation to it is,
- A simple ASP.NET code to handle the web requests.
- SQL Server database connection
- Web page to display it
Handling web request
You can easily handle the web requests of uploading the files, a simple request for that is like,
if(IsPost) {
var image = WebImage.GetImageFromRequest();
}
SQL Server setup
SQL Server, mostly CE is used but Microsoft is now deprecating this version, so it is better for you to use the SQL Server Express, or any other version if required, all you need to make sure is that the connection is established and that the columns are good to store the data. By "good to store" I mean that the data type for each of the column must be set, in SQL Server, images file, (or generally files) are stored in the form of bytes, so the Image data type in the SQL Server is for saving the files, as called the BLOBS or bytes etc. So to store these files in the database you need to have a column of type Image.
Also, there is a limit on this Image data type of the SQL too, as stated in the document link:
Quote:
Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes.
http://msdn.microsoft.com/en-us/library/ms187993.aspx[
^]
Saving and getting files from SQL Server Database
This is the task where you need to be told about how to and where to write the code. ASP.NET MVP Mike Brind has written an excellent article for this,
http://www.mikesdotnetting.com/Article/148/Save-And-Retrieve-Files-From-a-Sql-Server-CE-Database-with-WebMatrix[
^]
You can read the above article to learn specifically about ASP.NET and the SQL Server CE. There is no general difference between working of SQL Server and SQL Server CE, just a bit of feature lackages like stored procedures aren't present in the SQL Server CE. Below is another article posted at CodeProject relating to this one, but I myself prefer the Mike's article.
C# Save and Load Image from Database[
^]
Personal opinion
Through my personal experience of developmental progress, I have learnt that saving the files inside the Database isn't a good way of storing the files. You should always save the files in the File System, and just save their links in the database.