繁体   English   中英

无法将大文件(> 50MB)上传到SharePoint 2010文档库

[英]Cannot upload large (>50MB) files to SharePoint 2010 document library

我正在尝试将大文件上传到文档库,但是几秒钟后它失败了。 上载单个文档失败,而上载多个文档仅显示失败消息。 我已经将Web应用程序上的文件大小限制设置为500MB,并将IIS请求长度设置为相同(来自此Blog ),并增加了IIS超时以作适当的选择。 我还错过其他尺寸的帽子吗?

更新我尝试了一些大小不一的文件,任何50MB或以上的文件都失败了,因此我假设某些地方仍设置为Webapp默认值。

更新2刚刚尝试使用以下Powershell上传:

$web = Get-SPWeb http://{site address}
$folder = $web.GetFolder("Site Documents")
$file = Get-Item "C:\mydoc.txt" // ~ 150MB
$folder.Files.Add("SiteDocuments/mydoc.txt", $file.OpenRead(), $false)

并获得此异常:

Exception calling "Add" with "3" argument(s): "<nativehr>0x80070003</nativehr><nativestack></nativestack>There is no file with URL 'http://{site address}/SiteDocuments/mydoc.txt' in this Web."

令我感到奇怪的是,文件在上传之前是不存在的? 注意,尽管文档库的名称为Site Documents ,但其URL为SiteDocuments 不知道为什么

您确定更新了正确的Web应用程序吗? 文件类型是否被服务器阻止? 您的内容数据库中是否有足够的空间? 在那之后,我将检查ULS日志,看看是否还有另一个错误,因为看来您碰到了3个点也需要更新。

要上传大文件,可以使用PUT方法而不是其他方式来上传文档。 通过使用put方法,您可以将文件直接保存到内容数据库中。 见下面的例子

注意:以下代码的缺点是您无法捕获直接负责上传的对象,换句话说,您无法直接更新上传文档的其他自定义属性。

public static bool UploadFileToDocumentLibrary(string sourceFilePath, string targetDocumentLibraryPath)
    {
        //Flag to indicate whether file was uploaded successfuly or not
        bool isUploaded = true;
        try
        {
            // Create a PUT Web request to upload the file.
            WebRequest request = WebRequest.Create(targetDocumentLibraryPath);

            //Set credentials of the current security context
            request.Credentials = CredentialCache.DefaultCredentials;
            request.Method = “PUT”;

            // Create buffer to transfer file
            byte[] fileBuffer = new byte[1024];

            // Write the contents of the local file to the request stream.
            using (Stream stream = request.GetRequestStream())
            {
                //Load the content from local file to stream
                using (FileStream fsWorkbook = File.Open(sourceFilePath, FileMode.Open, FileAccess.Read))
                {
                    //Get the start point
                    int startBuffer = fsWorkbook.Read(fileBuffer, 0, fileBuffer.Length);
                    for (int i = startBuffer; i > 0; i = fsWorkbook.Read(fileBuffer, 0, fileBuffer.Length))
                    {
                        stream.Write(fileBuffer, 0, i);
                    }

                }
            }

            // Perform the PUT request
            WebResponse response = request.GetResponse();

            //Close response
            response.Close();
        }
        catch (Exception ex)
        {
            //Set the flag to indiacte failure in uploading
            isUploaded = false;
        }

        //Return the final upload status
        return isUploaded;
    }

这是调用此方法的示例

UploadFileToDocumentLibrary(@”C:\test.txt”, @”http://home-vs/Shared Documents/textfile.pdf”);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM