• 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);

  • 相关阅读:
    GCC内置函数
    父类子类的拷贝构造与赋值
    外传三 动态内存申请的结果
    外传二 函数的异常规格说明
    外传一 异常处理深度解析
    第69课 技巧,自定义内存管理
    第68课 拾遗,令人迷惑的写法
    第67课 经典问题解析五
    第66课 C++中的类型识别
    第65课 C++中的异常处理(下)
  • 原文地址:https://www.cnblogs.com/xdanny/p/12586167.html
Copyright © 2020-2023  润新知