
ASP.NET C# code to stream a download from a SQL server Filestream
- or -
Post a project like this3351
£40(approx. $53)
- Posted:
- Proposals: 2
- Remote
- #1033472
- PRE-FUNDED
- Completed
Description
Experience Level: Intermediate
General information for the website: A file sharing website
Kind of development: Customization of existing website
Num. of web pages/modules: 1
Description of every page/module: The code below is designed to allow me to download a file from a SQL database using ASP.NET.
I need the following code modified to allow me to download huge files (larger than 2GB) using a browser. At present I am getting an out of memory error message, which I think is because the byte array can only hold items up to 2GB and possibly because I am using visual studio instead of a full blown IIS. I need the code changed to stream the information from the SQL server, not copy it into a byte array and then return that.
I will need comments added to your code so I can change it for future use.
public FileContentResult VideoSingle()
{
Debug.WriteLine("Controller started");
string filename = "TheFileNameOfTheFile";
byte[] btImage = null;
string customer = "A10000001VICKERS.dbo.VIDEOS";
string idVideo = "16663406-9594-409D-93C5-85BB1AAB0B0D";
string sqlParameters = String.Format(@"SELECT filestreamvideo FROM {0} where idvideo=@VideoID", customer);
string connectionString = ConfigurationManager.ConnectionStrings["ConnectToSQL"].ConnectionString;
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
using (SqlCommand sqlCommand = new SqlCommand(sqlParameters, sqlConnection))
{
sqlCommand.Parameters.AddWithValue("@VideoID", idVideo);
sqlConnection.Open();
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.Read())
{
btImage = (byte[])sqlDataReader["filestreamvideo"];
}
}
sqlConnection.Close();
}
return File(btImage, "mp4", filename + ".mp4");
}
Description of requirements/features: Create a asp.net controller to return a SQL Filestream as a file download that can deal with files larger than 2GB (potentially up to 16GB)
Specific technologies required: C# ASP.NET SQL
Extra notes:
Kind of development: Customization of existing website
Num. of web pages/modules: 1
Description of every page/module: The code below is designed to allow me to download a file from a SQL database using ASP.NET.
I need the following code modified to allow me to download huge files (larger than 2GB) using a browser. At present I am getting an out of memory error message, which I think is because the byte array can only hold items up to 2GB and possibly because I am using visual studio instead of a full blown IIS. I need the code changed to stream the information from the SQL server, not copy it into a byte array and then return that.
I will need comments added to your code so I can change it for future use.
public FileContentResult VideoSingle()
{
Debug.WriteLine("Controller started");
string filename = "TheFileNameOfTheFile";
byte[] btImage = null;
string customer = "A10000001VICKERS.dbo.VIDEOS";
string idVideo = "16663406-9594-409D-93C5-85BB1AAB0B0D";
string sqlParameters = String.Format(@"SELECT filestreamvideo FROM {0} where idvideo=@VideoID", customer);
string connectionString = ConfigurationManager.ConnectionStrings["ConnectToSQL"].ConnectionString;
using (SqlConnection sqlConnection = new SqlConnection(connectionString))
{
using (SqlCommand sqlCommand = new SqlCommand(sqlParameters, sqlConnection))
{
sqlCommand.Parameters.AddWithValue("@VideoID", idVideo);
sqlConnection.Open();
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.Read())
{
btImage = (byte[])sqlDataReader["filestreamvideo"];
}
}
sqlConnection.Close();
}
return File(btImage, "mp4", filename + ".mp4");
}
Description of requirements/features: Create a asp.net controller to return a SQL Filestream as a file download that can deal with files larger than 2GB (potentially up to 16GB)
Specific technologies required: C# ASP.NET SQL
Extra notes:

Christopher V.
100% (9)Projects Completed
10
Freelancers worked with
10
Projects awarded
63%
Last project
18 Apr 2025
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies