sharepoint中的最大文件上载大小

时间:2011-06-27 10:46:43

标签: sharepoint c#-4.0 sharepoint-2010 c#-3.0

我使用以下方法将文档上传到sharepoint文档库。 但是,在执行查询时 - 获取以下错误: Message =“远程服务器返回错误:(400)Bad Request。”

文件失败超过1mb,所以我通过sharepoint UI测试了它,并且成功上传了相同的文件。

对问题是什么的任何想法?是否可以流式传输文件而不是1个大文件块?有问题的文件只有3mb ..

private ListItem UploadDocumentToSharePoint(RequestedDocumentFileInfo requestedDoc, ClientContext clientContext)
{
    try
    {
        var uploadLocation = string.Format("{0}{1}/{2}", SiteUrl, Helpers.ListNames.RequestedDocuments,
                                           Path.GetFileName(requestedDoc.DocumentWithFilePath));

        //Get Document List
        var documentslist = clientContext.Web.Lists.GetByTitle(Helpers.ListNames.RequestedDocuments);
        var fileCreationInformation = new FileCreationInformation
                                          {
                                              Content = requestedDoc.ByteArray,
                                              Overwrite = true,
                                              Url = uploadLocation //Upload URL,
                                          };

        var uploadFile = documentslist.RootFolder.Files.Add(fileCreationInformation);
        clientContext.Load(uploadFile);
        clientContext.ExecuteQuery();

        var item = uploadFile.ListItemAllFields;
        item["Title"] = requestedDoc.FileNameParts.FileSubject;
        item["FileLeafRef"] = requestedDoc.SharepointFileName;
        item.Update();
    }
    catch (Exception exception)
    {
        throw new ApplicationException(exception.Message);
    }
    return GetDocument(requestedDoc.SharepointFileName + "." + requestedDoc.FileNameParts.Extention, clientContext);
}

编辑:我确实找到了关于我的问题的以下ms页面(这看起来与他们提出的问题相同)http://support.microsoft.com/kb/2529243但似乎没有提供解决方案。

1 个答案:

答案 0 :(得分:2)

确定在这里找到解决方案: http://blogs.msdn.com/b/sridhara/archive/2010/03/12/uploading-files-using-client-object-model-in-sharepoint-2010.aspx

我需要将文档存储在托管该文件的服务器上,然后使用我在下面的代码中完成的文件流上传过程:

    private ListItem UploadDocumentToSharePoint(RequestedDocumentFileInfo requestedDoc, ClientContext clientContext)
    {
        try
        {
            using(var fs = new FileStream(string.Format(@"C:\[myfilepath]\{0}", Path.GetFileName(requestedDoc.DocumentWithFilePath)), FileMode.Open))
            {
                File.SaveBinaryDirect(clientContext, string.Format("/{0}/{1}", Helpers.ListNames.RequestedDocuments, requestedDoc.FileName), fs, true);
            }
        }
        catch (Exception exception)
        {
            throw new ApplicationException(exception.Message);
        }
        return GetDocument(requestedDoc.SharepointFileName + "." + requestedDoc.FileNameParts.Extention, clientContext);
    }