zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    1407251735-hd-美素数.cpp
    [Javascript] IO Functor
    [AngularJS] Test an Angular Component with $componentController
    [AngularJS] Isolate State Mutations in Angular Components
    [Jest] Track project code coverage with Jest
    [Javascript] Either Functor
    [Javascript] Maybe Functor
    [AngualrJS] ng-strict-di
    [Ramda] Simple log function for debugging Compose function / Using R.tap for logging
    [Jest] Test JavaScript with Jest
  • 原文地址:https://www.cnblogs.com/xdanny/p/12586167.html
Copyright © 2011-2022 走看看