Wednesday, June 16, 2010

How to upload a large file in Asp.net ?

When we try to upload a large file (usually of size in MB/GB), we get an exception indicating server not responding.
This can be avoided by using <httpRuntime> section in the Web.config file.


<configuration>
<system.web>
<httpRuntime> </httpRuntime>
</system.web>
</configuration>

The parameters of httpRuntime are ,
<httpRuntime
executionTimeout = "number"
maxRequestLength = "number"
requestLengthDiskThreshold = "number"
useFullyQualifiedRedirectUrl = "[True|False]"
minFreeThreads = "number"
minLocalRequestFreeThreads = "number"
appRequestQueueLimit = "number"
enableKernelOutputCache = "[True|False]"
enableVersionHeader = "[True|False]"
apartmentThreading = "[True|False]"
requireRootedSaveAsPath = "[True|False]"
enable = "[True|False]"
sendCacheControlHeader = "[True|False]"
shutdownTimeout = "number"
delayNotificationTimeout = "number"
waitChangeNotification = "number"
maxWaitChangeNotification = "number"
enableHeaderChecking = "[True|False]"
/>

More description you can find in the below link.

http://msdn.microsoft.com/en-us/library/e1f13641.aspx

The following example demonstrates how I solved the issue of uploading large file.

<system.web>
<httpRuntime executionTimeout="999999" maxRequestLength="2097151" />
</system.web>

*Please leave a comment before you leave.


No comments:

Post a Comment