使用asp.net将大文件上传到sharepoint文档库 [英] Upload large file into sharepoint document library using asp.net

查看:62
本文介绍了使用asp.net将大文件上传到sharepoint文档库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将文件从asp.net应用程序上传到sharepoint文档库.
最多可以上传50MB的文件.当我上传超过50MB的文件时,不允许.

我的IIS是IIS 6.0.

该怎么做.

在WEB应用程序常规设置下的sharepoint文档库中,我已经设置了

文件上传大小为200MB,但不起作用.

和web.config我添加了这个:

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


这是我的代码:
--------------------

受保护的无效btnUpload_Click(对象发送者,EventArgs e)
{
字符串uploadFilePath = @"E:\ New Folder \";
字符串sharePointListPath =
"sharepointserverpath";




如果(FileUpload1.HasFile)
试试
{
FileUpload1.SaveAs(
uploadFilePath + FileUpload1.FileName);

Label1.Text =文件名:" +
FileUpload1.PostedFile.FileName +"
" +
FileUpload1.PostedFile.ContentLength +"bytes
" +
内容类型:" +
FileUpload1.PostedFile.ContentType;

UploadFileToSharePoint(
UploadedFilePath + FileUpload1.FileName,
sharePointListPath + FileUpload1.FileName);
}
catch(ex ex例外)
{
Label1.Text ="ERROR:" + ex.Message.ToString();
}
其他
{
Label1.Text =您尚未指定文件.";
}
}

受保护的void UploadFileToSharePoint(字符串UploadedFilePath,字符串SharePointPath)
{
Web响应;响应=空;

试试
{
//创建一个PUT Web请求以上传文件.
WebRequest请求= WebRequest.Create(SharePointPath);

request.Credentials = CredentialCache.DefaultCredentials;

request.Method ="PUT";

//分配1 KB的缓冲区以传输文件内容.
//您可以根据需要调整缓冲区大小,具体取决于
//正在上传的文件的数量和大小.
字节[]缓冲区=新字节[1024];

//将本地文件的内容写入
//请求流.
使用(Stream stream = request.GetRequestStream())
使用(FileStream fsWorkbook = File.Open(UploadedFilePath,
FileMode.Open,FileAccess.Read))
{
int i = fsWorkbook.Read(buffer,0,buffer.Length);

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

//发出PUT请求.
响应= request.GetResponse();
}
catch(ex ex例外)
{
扔前;
}
终于
{
response.Close();
}
}

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();
}
}

推荐答案

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>


请浏览下面的所有链接.

将大文件上传到IIS/ASP.NET [设置Web.config以允许通过以下方式上传大文件ASP .NET应用程序 [ SharePoint大文件上传配置 [ ^ ].
将大文件上传到Web服务器-ASP.net [
Please go through all the links below.

Uploading Large Files to IIS / ASP.NET[^].
Setting up Web.config to allow uploading of large files by ASP .NET applications[^].
SharePoint Large File Upload Configuration[^].
Large File Upload to web server - ASP.net[^].

Hope they help...


这篇关于使用asp.net将大文件上传到sharepoint文档库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆