gpt4 book ai didi

c# - 通过 c# Web 服务将 100mb 以上的大文件上传到 Sharepoint 2010

转载 作者:行者123 更新时间:2023-11-30 22:29:15 25 4
gpt4 key购买 nike

我无法将大文件上传到 Sharepoint 2010。我使用的是 Visual Studio 2010 和 C# 语言。我从网上找到的内容中尝试了多种方法,但没有任何效果。我已将设置和配置文件更改为允许的最大上传限制,但仍然没有。我将 copy.asmx 用于小文件,它工作正常,当文件太大并抛出异常时我尝试 UploadDataAsync 但这不起作用。请看下面的代码...

非常感谢任何/所有帮助。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace ListsService
{

public class UploadDocumentcs
{
public string UploadResult { get; set; }
public string Errors { get; set; }
public UploadDataCompletedEventHandler WebClient_UploadDataCompleted { get; set; }
public byte[] content { get; set; }

public void UploadDocumentToSP(string localFile, string remoteFile)
{
string result = string.Empty;
SPCopyService.CopySoapClient client = new SPCopyService.CopySoapClient();

string sUser = "user";
string sPwd = "pwd";
string sDomain = "dmn";
System.Net.NetworkCredential NC = new System.Net.NetworkCredential(sUser, sPwd, sDomain);

client.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
client.ClientCredentials.Windows.ClientCredential = NC;

try
{
client.Open();

string url = "http://SP/TestLibrary/";
string fileName = localFile.Substring(localFile.LastIndexOf('\\'), (localFile.Length - localFile.LastIndexOf('\\')));
fileName = fileName.Remove(0, 1);
string[] destinationUrl = { url + fileName };

System.IO.FileStream fileStream = new System.IO.FileStream(localFile, System.IO.FileMode.Open);
byte[] content = new byte[(int)fileStream.Length];
fileStream.Read(content, 0, (int)fileStream.Length);
fileStream.Close();

// Description Information Field
SPCopyService.FieldInformation descInfo = new SPCopyService.FieldInformation
{
DisplayName = "Description",
Type = SPCopyService.FieldType.File,
Value = "Test file for upload"
};

SPCopyService.FieldInformation[] fileInfoArray = { descInfo };

SPCopyService.CopyResult[] arrayOfResults;

uint result2 = client.CopyIntoItems(fileName, destinationUrl, fileInfoArray, content, out arrayOfResults);

// Check for Errors
foreach (SPCopyService.CopyResult copyResult in arrayOfResults)
{
string msg = "====================================" +
"SharePoint Error:" +
"\nUrl: " + copyResult.DestinationUrl +
"\nError Code: " + copyResult.ErrorCode +
"\nMessage: " + copyResult.ErrorMessage +
"====================================";


Errors = string.Format("{0};{1}", Errors, msg);
}
UploadResult = "File uploaded successfully";

}
catch (OutOfMemoryException)
{
System.Uri uri = new Uri("http://bis-dev-srv2:300/DNATestLibrary/");
(new System.Net.WebClient()).UploadDataCompleted += new UploadDataCompletedEventHandler(WebClient_UploadDataCompleted);
(new System.Net.WebClient()).UploadDataAsync(uri, content);

}

finally
{
if (client.State == System.ServiceModel.CommunicationState.Faulted)
{
client.Abort();
UploadResult = "Upload aborted due to error";
}

if (client.State != System.ServiceModel.CommunicationState.Closed)
{
client.Close();
}
}
}


void WcUpload_UploadDataCompleted(object sender, UploadDataCompletedEventArgs e)
{

if (e != null)
{
UploadResult = "Upload Unuccessful";
}
else
{
UploadResult = "Upload Successful";
//throw new NotImplementedException();
}
}
}
}

最佳答案

肖恩
为了让它工作,您必须更改 SharePoint 配置以增加上传限制和超时。下面的链接显示了使大文件上传正常工作的必要步骤。

http://blogs.technet.com/b/sharepointcomic/archive/2010/02/14/sharepoint-large-file-upload-configuration.aspx

关于c# - 通过 c# Web 服务将 100mb 以上的大文件上传到 Sharepoint 2010,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10300550/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com