• CSOM 转移文档到其它目录


    先创建一个项目,然后写一个转移方法

    public static void movefiles()

    {

    try{

      ClientContent clientContext = new ClientContext(siteUrl);

      clientContext.RequestTimeout = Timeout.Infinite;

      var user name = "";

      var password ="";

      clientContext.Credentials = new NetworkCredential(username,password,domain);

      clientContext.Credentials = CredentialCache.DefaultCredentials;

      Guid listId = new Guid("A9999---");

      Web web = clientContext.Web;

      List docList = web.Lists.GetById(listId);

      CamlQuery camlQuery = new CamlQuery();

      camlQuery.ViewXml = "";

      ListItemCollection items = docList.GetItems(camlQuery);

      clientContext.Load(docList);

      clientContext.Load(items);

      clientContex.ExecuteQuery();

      int count = 1;

      foreach(var item in items)

      {

      Console.WriteLine("共"+items.Count + "个");

      SP. File file = item.Fiel;

      clientContext.Load(file);

      clientContex.Load(web);

      clientContex.ExecuteQuery();

      string destLocation = "/site/library/folder/"+file.name;

      //FileInfomation fileInfo = SP.File.OpenBinaryDirect(clientContex,file.ServierRelativeUrl);

      //SP.File.SaveBinaryDirect(clientContex,destLocation,fileInfo.Stream,true);

      if(item.FileSystemObjectType == FileSytemObjectType.File)

      {

      file.MoveTo(destLocation,MoveOperations.Overwrite);

      clientContex.ExecuteQuery();

      var uploadfile = clientContext.Web.GetFileByServerRelatioveUrl(destLocation);

      var listitem = uploadfile.ListItemAllFields;

      listitem["ContentTypeId"] = "0x0....";

      listitem.Update();

      clientContext.ExecuteQuery();

        count ++;

      clientContext.Dispose();

      Console.WriteLine("完成。")

           }catch(Exception e)

      {

      Console.WriteLine("{0}",e.Message);

      return;

      }

    }

    下载文档的方法:

    FileInformation fInfo = SP.File.OpenBinaryDirect(clientContext,item["FileRef").ToString();

    stream s= fInfo.Stream;

    string saveTo=@"D:\folder"+filename;

    FileStream writeStream = new FileStream(saveTo,FileMode.Create,FileAccess.Write);

    ReadWriteStream(s,writeStream);

  • 相关阅读:
    控制结构(Scala)
    《基于Spark的大数据访存行为跨层分析工具》学习笔记
    函数式对象(Scala)
    心脏病预测(SVM模型)
    类、对象、基础类型、操作(Scala)
    ElementUI对话框(dialog)提取为子组件
    ElementUI+命名视图实现复杂顶部和左侧导航栏
    ElementUI 复杂顶部和左侧导航栏实现
    Vue页面手动刷新,导航栏激活项还原到初始状态问题解决方案
    elementUI动态数据表格(带分页)
  • 原文地址:https://www.cnblogs.com/xdanny/p/12586167.html
Copyright © 2020-2023  润新知