Uploading Large File to SQL

Discussion in 'ASP .Net' started by - Steve -, Jul 13, 2004.

  1. - Steve -

    - Steve - Guest

    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
    - Steve -, Jul 13, 2004
    #1
    1. Advertising

  2. - Steve -

    Kyril Magnos Guest

    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

    "- Steve -" <> wrote in message news:...
    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
    Kyril Magnos, Jul 13, 2004
    #2
    1. Advertising

  3. 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

    "- Steve -" <> wrote in message news:...
    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
    Steve C. Orr [MVP, MCSD], Jul 13, 2004
    #3
  4. - Steve -

    - Steve - Guest

    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


    "Steve C. Orr [MVP, MCSD]" <> wrote in message news:%...
    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

    "- Steve -" <> wrote in message news:...
    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
    - Steve -, Jul 13, 2004
    #4
  5. 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


    "- Steve -" <> wrote in message news:...
    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


    "Steve C. Orr [MVP, MCSD]" <> wrote in message news:%...
    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

    "- Steve -" <> wrote in message news:...
    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
    Steve C. Orr [MVP, MCSD], Jul 13, 2004
    #5
  6. - Steve -

    Joe Fallon Guest

    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



    "- Steve -" <> wrote in message news:...
    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


    "Steve C. Orr [MVP, MCSD]" <> wrote in message news:%...
    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

    "- Steve -" <> wrote in message news:...
    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
    Joe Fallon, Jul 15, 2004
    #6
  7. - Steve -

    - Steve - Guest

    Any plans to cover this in ASP.net 2.0?

    --

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


    "Joe Fallon" <> wrote in message news:...
    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



    "- Steve -" <> wrote in message news:...
    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


    "Steve C. Orr [MVP, MCSD]" <> wrote in message news:%...
    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

    "- Steve -" <> wrote in message news:...
    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
    - Steve -, Jul 19, 2004
    #7
  8. - Steve -

    Joe Fallon Guest

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




    "- Steve -" <> wrote in message news:...
    Any plans to cover this in ASP.net 2.0?

    --

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


    "Joe Fallon" <> wrote in message news:...
    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



    "- Steve -" <> wrote in message news:...
    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


    "Steve C. Orr [MVP, MCSD]" <> wrote in message news:%...
    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

    "- Steve -" <> wrote in message news:...
    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
    Joe Fallon, Jul 20, 2004
    #8
  9. - Steve -

    Yu Chen Guest

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

    "Joe Fallon" <> wrote in message news:<>...
    > 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
    >
    >
    >
    > "- Steve -" <> wrote in message
    > news:...
    > 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
    >
    >
    > "Steve C. Orr [MVP, MCSD]" <> wrote in message
    > news:%...
    > 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
    >
    > "- Steve -" <> wrote in message
    > news:...
    > 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
    >
    >
    > --
    Yu Chen, Jul 20, 2004
    #9
  10. - Steve -

    Joe Fallon Guest

    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" <> wrote in message
    news:...
    > Joe,
    > Do you happen to remember how to retrieve that old thread?
    > Yu
    >
    > "Joe Fallon" <> wrote in message

    news:<>...
    > > 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
    > >
    > >
    > >
    > > "- Steve -" <> wrote in message
    > > news:...
    > > 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
    > >
    > >
    > > "Steve C. Orr [MVP, MCSD]" <> wrote in message
    > > news:%...
    > > 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
    > >
    > > "- Steve -" <> wrote in message
    > > news:...
    > > 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
    > >
    > >
    > > --
    Joe Fallon, Jul 21, 2004
    #10
  11. - Steve -

    - Steve - Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:...
    >> Joe,
    >> Do you happen to remember how to retrieve that old thread?
    >> Yu
    >>
    >> "Joe Fallon" <> wrote in message

    > news:<>...
    >> > 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
    >> >
    >> >
    >> >
    >> > "- Steve -" <> wrote in message
    >> > news:...
    >> > 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
    >> >
    >> >
    >> > "Steve C. Orr [MVP, MCSD]" <> wrote in message
    >> > news:%...
    >> > 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
    >> >
    >> > "- Steve -" <> wrote in message
    >> > news:...
    >> > 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
    >> >
    >> >
    >> > --

    >
    >
    - Steve -, Jul 21, 2004
    #11
  12. - Steve -

    Joe Fallon Guest

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

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



    "- Steve -" <> wrote in message
    news:OpX$$...
    > 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, Jul 22, 2004
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Uploading large file

    David, Jan 20, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    438
    Hans Kesting
    Jan 20, 2005
  2. Dung Ping
    Replies:
    10
    Views:
    946
    Chaddy2222
    Jan 16, 2006
  3. Nayana

    problem of uploading large file in asp

    Nayana, Jan 7, 2005, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    95
    Roland Wolters
    Jan 10, 2005
  4. Bram Kuijpers

    problem uploading large file with webservice

    Bram Kuijpers, Sep 27, 2006, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    178
  5. Paresh Shah
    Replies:
    1
    Views:
    124
    Paresh Shah
    Jul 14, 2003
Loading...

Share This Page