Click here to Skip to main content
12,623,511 members (29,250 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET SharePoint
I am uploading file from asp.net application to sharepoint document library.
upto 50MB Files uploading well.when i upload more than 50MB its not allowing.

my IIS is IIS 6.0.

how to do that.

in sharepoint document library under WEB APPLICATION GENERAL SETTING i have set

file upload size to 200MB But its not working.

and web.config i added this:

<httpruntime executiontimeout="3600">
maxRequestLength="200000"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"/>


here is my code:
--------------------

protected void btnUpload_Click(object sender, EventArgs e)
{
string uploadedFilePath = @"E:\New Folder\";
string sharePointListPath =
"sharepointserverpath";




if (FileUpload1.HasFile)
try
{
FileUpload1.SaveAs(
uploadedFilePath + FileUpload1.FileName);

Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "
" +
FileUpload1.PostedFile.ContentLength + " bytes
" +
"Content type: " +
FileUpload1.PostedFile.ContentType;

UploadFileToSharePoint(
uploadedFilePath + FileUpload1.FileName,
sharePointListPath + FileUpload1.FileName);
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
}

protected void UploadFileToSharePoint(string UploadedFilePath,string SharePointPath)
{
WebResponse response =null;

try
{
// Create a PUT Web request to upload the file.
WebRequest request = WebRequest.Create(SharePointPath);

request.Credentials = CredentialCache.DefaultCredentials;

request.Method = "PUT";

// Allocate a 1 KB buffer to transfer the file contents.
// You can adjust the buffer size as needed, depending on
// the number and size of files being uploaded.
byte[] buffer = new byte[1024];

// Write the contents of the local file to the
// request stream.
using (Stream stream = request.GetRequestStream())
using (FileStream fsWorkbook = File.Open(UploadedFilePath,
FileMode.Open, FileAccess.Read))
{
int i = fsWorkbook.Read(buffer, 0, buffer.Length);

while (i > 0)
{
stream.Write(buffer, 0, i);
i = fsWorkbook.Read(buffer, 0, buffer.Length);
}
}

// Make the PUT request.
response = request.GetResponse();
}
catch (Exception ex)
{
throw ex;
}
finally
{
response.Close();
}
}

Posted 5-Aug-12 22:47pm
Updated 7-Aug-12 0:11am
v6
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Generally, the uploading limit of ASP.NET FileUploader is 4MB. But you can increase the limit of length of uploaded file by using the following code into your web.config file in your website.
 
<httpruntime maxrequestlength="20480" executiontimeout="600">
</httpruntime>
  Permalink  
Comments
Unareshraju 6-Aug-12 4:56am
   
http://www.webdavsystem.com/server/documentation/large_files_iis_asp_net
oliver grace 6-Aug-12 5:07am
   
<httpruntime maxrequestlength="20480" executiontimeout="600">


I have tried httpruntime but i am getting this error.
ERROR: Object reference not set to an instance of an object.
Unareshraju 6-Aug-12 5:29am
   
he source code that generated this unhandled exception can only be shown when compiled in debug mode. To enable this, please follow one of the below steps, then request the URL:

1. Add a "Debug=true" directive at the top of the file that generated the error. Example:

<%@ Page Language="C#" Debug="true" %>

or:

2) Add the following section to the configuration file of your application:

<configuration>

<system.web>

<compilation debug="true">
Unareshraju 6-Aug-12 5:32am
   
configuration
system.web
compilation debug="true"/
/system.web
/configuration

in the tags
oliver grace 6-Aug-12 5:46am
   
still I have same error :
ERROR: Object reference not set to an instance of an object
Unareshraju 6-Aug-12 5:57am
   
if possible can u show you r code?
Unareshraju 6-Aug-12 5:58am
   
please see her for more details where u did wrong.
http://forums.aspfree.com/net-development-11/common-causes-of-object-reference-not-set-to-an-instance-45799.html
Unareshraju 6-Aug-12 5:59am
   
http://support.microsoft.com/kb/810098
oliver grace 6-Aug-12 6:14am
   
hi, I have added my code here:
http://www.codeproject.com/Questions/435183/how-to-set-large-file-set-in-asp-net

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 7 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100