You must Sign In to post a response.
  • Category: .NET

    Unable to upload 2gb file


    I am trying to upload 2 GB file on to a file location.
    I have the following code in .cs file

    if (FileUpload1.HasFile && FileUpload1.FileBytes.Length < 2147483)
    string filename = Path.GetFileName(FileUpload1.FileName);

    string SaveLocation = Server.MapPath("UploadedFiles") + "\\" + filename;

    Response.Write("The file has been uploaded.");
    catch (Exception ex)
    throw ex;

    following settings in web.config file:-
    <compilation debug="true" strict="false" explicit="true" targetFramework="4.5">
    <add assembly="System.Design, Version=, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Web.Extensions.Design, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add assembly="System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
    <httpRuntime targetFramework="4.5" maxRequestLength="2097152" executionTimeout="32247"/>

    <gcAllowVeryLargeObjects enabled="true" />
    <requestLimits maxAllowedContentLength="2147483648" />


    still iam getting the following error:-

    Exception of type 'System.OutOfMemoryException' was thrown.

    Let me know if anyone has solution for this problem.
  • #766476

    As per error details "System.OutOfMemoryException" you don't have enough space to save that file in your local system, recheck the space in your local system if you think there is no proper space delete some files and try to reload it again, if you still face the same problem let us know.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #766481
    "Exception of type 'System.OutOfMemoryException' was thrown"
    problem usually occurs when some process such as loading huge data to memory stream and your system memory is not capable of storing so much of data. Try clearing temp folder by giving the command

    start -> run -> %temp%

  • #766484

    Thanks for the reply. I have more space on my disk around 236 Gb. So I dont know where it went wrong since there is enough space on disk.Please let me know if any one has any other solutions

  • #766488
    You are using following for runtime
    < httpRuntime targetFramework="4.5" maxRequestLength="2097152" executionTimeout="32247"/ >

    You have to add one more property "requestLengthDiskThreshold" and also change the values. In the config file you have to add the following.
    Can you try the following

    < httpRuntime maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647"/ >

    By Nathan
    Direction is important than speed

  • #766493

    try this code

    Add this code in Web.config-

    <httpRuntime executionTimeout="2400" maxRequestLength="40960" />


    <httpRuntime maxRequestLength="2097151" />


    <httpRuntime executionTimeout="110" maxRequestLength="40000" />

    The maximum size you can set in ASP.NET is 2097151Kb = 2Gb.

    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766494

    you can go through below link for large file upload


    Name : Dotnet Developer-2015
    Email Id :

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #766505
    Please check can you put chunks of data to upload the file. One of my resource I will give a referral link as the problem is different from it but it gives some idea

    using webclient to upload a file to server

    using ftp client to upload a file to server


  • #766510
    Try enabling 3GB switch of your server computer from boot.ini file, which helps to use lots/maximum of its memory.
    Follow steps given in below URL to enable/disable it:
    Find discussion over server memory management using 3GB switch over here:

  • #766602
    while uploading file system uses assigned memory, By default ASP.NET is allowed 60% of available memory, You can change that value to, say 80% to give ASP.NET more room, but this is not recommend. Consider other options, like uploading file in chunks etc (you can increase it in process model memory, it Configures the ASP.NET process model settings on a Microsoft Internet Information Services (IIS) Web server)
    see given link
    One solution would be to use MultipartFormDataStreamProvider instead of the MultipartMemoryStreamProvider to avoid the out of memory exception during the call, see below snippet


    see below link

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • Sign In to post your comments