SPO&CSOM&无法将文档上传到文档库,但是我可以创建一个文件夹

时间:2019-12-08 01:48:48

标签: sharepoint sharepoint-online csom

尝试将文档上载到文档库时出现列表视图阈值问题。让我给你讲故事的背景。

  • 我的网站位于SPO上,我正在使用CSOM创建一个文件夹,然后将上传的文档添加到该文件夹​​中。
  • 我用来向SPO进行身份验证的服务帐户是网站集管理员。
  • 我的CSOM代码可以创建文件夹,但是无法将文档上传到该文件夹​​,因为SharePoint表示我们已经达到列表视图阈值。

  • 我们要上载文档的文档库中有超过2万个项目。

  • 我们仅使用的默认视图已选中一列,我们已为“标题”和“创建的”字段建立了索引,并且文档库使用了现代的体验。

一段时间以来,我们一直在使用相同的代码,但是截至2019年10月,一切都停止了工作。

有什么想法吗?下面提供的是我正在使用的代码 使用(ClientContext ctx = new ClientContext(SPUrl))                             {                                 ctx.Credentials =新的SharePointOnlineCredentials(spuser,securePassword);

import React, { useEffect, useState } from "react";
import app from "./config/base.js";
import axios from "axios";

export default class RepRequest extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      userInfo: [],
      fedSens: [],
      fedReps: []
    };
  }

  componentDidMount() {
    const items = [];
    app.auth().onAuthStateChanged(function(user) {
      if (user) {
        console.log("User is signed in");
        let db = app
          .firestore()
          .collection("user")
          .doc(user.uid);
        db.get().then(doc => {
          if (doc.exists) {
            console.log("Document data:", doc.data());
            items.push(doc.data());
          } else {
            console.log("No doc exists");
          }
        });
      }
      this.setState({ userInfo: items });
    });

    Promise.all([
      axios.get(
        `https://api.propublica.org/congress/v1/116/senate/members.json`,
        {
          headers: { "X-API-Key": "9wGKmWl3kNiiSqesJf74uGl0PtStbcP2mEzSvjxv" }
        }
      ),
      axios.get(
        `https://api.propublica.org/congress/v1/116/house/members.json`,
        {
          headers: { "X-API-Key": "9wGKmWl3kNiiSqesJf74uGl0PtStbcP2mEzSvjxv" }
        }
      )
    ]).then(([rest1, rest2]) => {
      this.setState({
        fedSens: rest1,
        fedReps: rest2
      });
    });
  }

  render() {
    if (this.state.fedReps.length <= 0)
      return (
        <div>
          <span>Loading...</span>
        </div>
      );
    else {
      console.log(this.state.fedReps);
      return <div>test</div>;
    }
  }
}

2 个答案:

答案 0 :(得分:0)

我的示例测试代码(该库有超过1万个文件)。

for

或者(该文件夹包含超过1万个文件)

List docs = context.Web.Lists.GetByTitle("largeLib1");                    
                var filePath = @"C:\Lee\template.xlsx";
                using (FileStream fs = new FileStream(filePath, FileMode.Open))
                {                        
                    FileCreationInformation flciNewFile = new FileCreationInformation();

                    flciNewFile.ContentStream = fs;
                    flciNewFile.Url = System.IO.Path.GetFileName(filePath);
                    flciNewFile.Overwrite = true;                    
                    Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(flciNewFile);
                    context.Load(uploadFile);
                    context.ExecuteQuery();
                } 

答案 1 :(得分:0)

我发现了问题所在。问题是调用ctx.Load(docs.RootFolder.Folders);我删除了这段代码,现在可以上传文档了。