Uploading Large File to SQL

S

- Steve -

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
K

Kyril Magnos

Hi Steve,

By default, ASP.NET has a 4MB upload posting limit. This can be changed in either machine.config or in the web.config by editing the <httpRuntime> tag and setting the maxRequestLength to something around 8192 (that will give you an 8 MB upload limit). The maxRequestLength attribute accepts any number, expressed in bytes.

Also, you will want to increase the executionTimeout attribute to something around 300 (5 minutes). By default, the value is 90 seconds, which is usually not long enough to upload a 5 MB file unless you are on a fast LAN. The executionTimeout attribute will also accept any number, expressed as seconds.

HTH,

Kyril

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
S

Steve C. Orr [MVP, MCSD]

You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
S

- Steve -

Okay that fixed the problem. However now when I'm upload a 500+mb file I run out of memory on the web server. Is there a better way to do this where I can stream the data in instead of creating such a huge byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
S

Steve C. Orr [MVP, MCSD]

Yes you need a lot of memory on your web server(s) if you're going to be dealing with files of that size.
Here's a third party product that improves the efficiency and scalability of such tasks:
www.safileup.com

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net


Okay that fixed the problem. However now when I'm upload a 500+mb file I run out of memory on the web server. Is there a better way to do this where I can stream the data in instead of creating such a huge byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
J

Joe Fallon

There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for over a year.
They came up with 90% of the code required to do this and then "went quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.
--
Joe Fallon



Okay that fixed the problem. However now when I'm upload a 500+mb file I run out of memory on the web server. Is there a better way to do this where I can stream the data in instead of creating such a huge byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
S

- Steve -

Any plans to cover this in ASP.net 2.0?

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for over a year.
They came up with 90% of the code required to do this and then "went quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.
--
Joe Fallon



Okay that fixed the problem. However now when I'm upload a 500+mb file I run out of memory on the web server. Is there a better way to do this where I can stream the data in instead of creating such a huge byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
J

Joe Fallon

I have read a lot of stuff and have not seen it.
But you never know...
--
Joe Fallon




Any plans to cover this in ASP.net 2.0?

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for over a year.
They came up with 90% of the code required to do this and then "went quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.
--
Joe Fallon



Okay that fixed the problem. However now when I'm upload a 500+mb file I run out of memory on the web server. Is there a better way to do this where I can stream the data in instead of creating such a huge byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a SQL server. It works fine when the file is under about 5mb, but bigger than that and after I hit submit (which eventually fires off this function) it get a 400 page error.

private void btnUpload_Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708
 
Y

Yu Chen

Joe,
Do you happen to remember how to retrieve that old thread?
Yu

Joe Fallon said:
There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for over
a year.
They came up with 90% of the code required to do this and then "went
quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.
--
Joe Fallon



Okay that fixed the problem. However now when I'm upload a 500+mb
file I run out of memory on the web server. Is there a better way to do
this where I can stream the data in instead of creating such a huge
byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a
SQL server. It works fine when the file is under about 5mb, but bigger
than that and after I hit submit (which eventually fires off this
function) it get a 400 page error.

private void btnUpload Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref
byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection
details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM
FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new
SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


--
 
J

Joe Fallon

Yes. I believe this is it:

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=55127

I am not aware of any plans to address this in 2.0.
It would be a nice surprise if it was!
--
Joe Fallon


Yu Chen said:
Joe,
Do you happen to remember how to retrieve that old thread?
Yu

"Joe Fallon" <[email protected]> wrote in message
There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for over
a year.
They came up with 90% of the code required to do this and then "went
quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.
--
Joe Fallon



Okay that fixed the problem. However now when I'm upload a 500+mb
file I run out of memory on the web server. Is there a better way to do
this where I can stream the data in instead of creating such a huge
byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to a
SQL server. It works fine when the file is under about 5mb, but bigger
than that and after I hit submit (which eventually fires off this
function) it get a 400 page error.

private void btnUpload Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType, ref
byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection
details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM
FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new
SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


--
 
S

- Steve -

Anyone have any experience with the solution posted at the very bottom. I"m
going to give it a whirl this afternoon.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


Joe Fallon said:
Yes. I believe this is it:

http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=55127

I am not aware of any plans to address this in 2.0.
It would be a nice surprise if it was!
--
Joe Fallon


Yu Chen said:
Joe,
Do you happen to remember how to retrieve that old thread?
Yu

"Joe Fallon" <[email protected]> wrote in message
There is no simple built in way to do it.
You should buy a 3rd party product if you need that ability.

There is an old thread (that is huge) that discussed this issue for
over
a year.
They came up with 90% of the code required to do this and then "went
quiet".
Then 3rd party controls started being sold.
Coincidence? I think not.
--
Joe Fallon



Okay that fixed the problem. However now when I'm upload a 500+mb
file I run out of memory on the web server. Is there a better way to
do
this where I can stream the data in instead of creating such a huge
byte[] variable.

--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


You can add or modify the following section in your web.config
file:

<configuration>
<system.web>
<httpRuntime maxRequestLength="4096" />
</system.web>
</configuration>

The above value (4096 KB) is the default maximum upload file size.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net

I have the following function that is supposed to save a file to
a
SQL server. It works fine when the file is under about 5mb, but bigger
than that and after I hit submit (which eventually fires off this
function) it get a 400 page error.

private void btnUpload Click(object sender, System.EventArgs e)

{

HttpPostedFile myFile = fileUpload.PostedFile;

byte[] myFileData = new byte[myFile.ContentLength];

myFile.InputStream.Read(myFileData, 0, myFile.ContentLength);

string fileName = Path.GetFileName(myFile.FileName);

SaveFileToSQL(fileName, myFile.ContentType, ref myFileData);

}

private string SaveFileToSQL(string fileName, string fileType,
ref
byte[] fileData)

{

SqlConnection myConnection = new SqlConnection(<connection
details>)


SqlDataAdapter myDataAdapter = new SqlDataAdapter("SELECT * FROM
FileX", myConnection);

SqlCommandBuilder myCommandBuilder = new
SqlCommandBuilder(myDataAdapter);

myConnection.Open();

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet, "FileX");

DataTable myDataTable = myDataSet.Tables["FileX"];

//insert data into SQL

DataRow myDataRow = myDataTable.NewRow();

myDataRow["FileName"] = fileName;

myDataRow["FileSize"] = fileData.Length;

myDataRow["ContentType"] = fileType;

myDataRow["FileData"] = fileData;

myDataTable.Rows.Add(myDataRow);

myDataAdapter.Update(myDataSet, "FileX");

myConnection.Close();

}


--

Steve Evans
Email Services
SDSU Foundation
(619) 594-0708


--
 
J

Joe Fallon

Steve,
The bottom of what?
The thread I posted?

If you get it working would you mind posting it for the benefit of all?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top