安装Microsoft.SharePointOnline.CSOM

1.根据sapno,更新状态

            List<ListItem> listAll = new List<ListItem>();using (ClientContext clientContext = new ClientContext(siteURL)){SecureString secureString = new SecureString();foreach (char c in DecryptAES.Decrypt(password).ToCharArray()) secureString.AppendChar(c);clientContext.Credentials = new SharePointOnlineCredentials(DecryptAES.Decrypt(username), secureString);List vendorList = clientContext.Web.Lists.GetByTitle("Information");CamlQuery camlQuery = new CamlQuery();foreach (DataRow dr in dt.Rows){string sapno = dr[0] == null ? "" : dr[0].ToString().Trim().Replace("\r\n", "");if (!string.IsNullOrEmpty(sapno)){camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='SAP_x002d_Code'/><Value Type='Text'>" + sapno + "</Value></Eq></Where></Query></View>";ListItemCollection listItems = vendorList.GetItems(camlQuery);clientContext.Load(listItems);clientContext.ExecuteQuery();if (listItems.Count > 0){foreach (ListItem item in listItems){if (item["_x72b6__x6001_"].ToString() == "禁用"){LoggerHelper.Monitor("已被禁用: ID=" + item["ID"] + ",VendorName=" + item["_x4f9b__x5e94__x5546__x4e2d__x65"] + ",SAPCode=" + item["SAP_x002d_Code"]);}else{item["_x72b6__x6001_"] = "禁用";item.Update();clientContext.ExecuteQuery();}}}else{LoggerHelper.Monitor("未查询到:" + sapno);}}}}

2.读取sharepoint list数据(循环,每次读取500行)

        public static List<ListItem> GetData(string siteUrl, string viewTitle){try{List<ListItem> listAll = new List<ListItem>();using (ClientContext clientContext = new ClientContext(siteUrl)){SecureString secureString = new SecureString();foreach (char c in DecryptAES.Decrypt(password).ToCharArray()) secureString.AppendChar(c);clientContext.Credentials = new SharePointOnlineCredentials(DecryptAES.Decrypt(username), secureString);List vendorList = clientContext.Web.Lists.GetByTitle(viewTitle);ListItemCollectionPosition itemPosition = null;while (true){CamlQuery camlQuery = new CamlQuery();camlQuery.ListItemCollectionPosition = itemPosition;camlQuery.ViewXml = @"<View><RowLimit>500</RowLimit></View>";//camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"></View>";ListItemCollection listItems = vendorList.GetItems(camlQuery);clientContext.Load(listItems);clientContext.ExecuteQuery();itemPosition = listItems.ListItemCollectionPosition;Console.WriteLine(itemPosition);var list = listItems.ToList();listAll.AddRange(list);if (itemPosition == null)break;Console.WriteLine(itemPosition.PagingInfo);}}return listAll;}catch (Exception ex){throw ex;}}

3.获取最近更新过的数据

        public static List<ListItem> GetIncData(string siteUrl, string viewTitle){try{string offset = ConfigurationManager.AppSettings["offset"];List<ListItem> listAll = new List<ListItem>();using (ClientContext clientContext = new ClientContext(siteUrl)){SecureString secureString = new SecureString();foreach (char c in DecryptAES.Decrypt(password).ToCharArray()) secureString.AppendChar(c);clientContext.Credentials = new SharePointOnlineCredentials(DecryptAES.Decrypt(username), secureString);List vendorList = clientContext.Web.Lists.GetByTitle(viewTitle);ListItemCollectionPosition itemPosition = null;CamlQuery camlQuery = new CamlQuery();camlQuery.ListItemCollectionPosition = itemPosition;//camlQuery.ViewXml = "<View><Query><Where>< Geq >< FieldRef Name =\"Modified\" />< Value Type = \"DateTime\" ><Today  OffsetDays = \"-1 \"></ Today ></ Value ></ Geq ></ Where ></ Query >< RowLimit>500</RowLimit></View>";camlQuery.ViewXml = "<View><Query><Where><Geq><FieldRef Name='Modified'/><Value Type='DateTime'><Today OffsetDays='" + offset + "'/></Value></Geq></Where></Query></View>";//camlQuery.ViewXml = "<View Scope=\"RecursiveAll\"></View>";ListItemCollection listItems = vendorList.GetItems(camlQuery);clientContext.Load(listItems);clientContext.ExecuteQuery();//itemPosition = listItems.ListItemCollectionPosition;//Console.WriteLine(itemPosition);var list = listItems.ToList();listAll.AddRange(list);//if (itemPosition == null)//    break;//Console.WriteLine(itemPosition.PagingInfo);}return listAll;}catch (Exception ex){throw ex;}}

C# Sharepoint 读取和更新相关推荐

  1. mysql dml语句 先读取在更新_事务的4个特性——ACID(原子性、一致性、隔离性和持久性)、更新丢失问题...

    两个并发事务同时访问数据库表相同的行时,可能存在以下三个问题: 1.幻想读:事务T1读取一条指定where条件的语句,返回结果集.此时事务T2插入一行新记录,恰好满足T1的where条件.然后T1使用 ...

  2. ASP.NET Core MVC 和 EF Core 教程 - 创建、读取、更新和删除

    作者:Tom Dykstra 和 Rick Anderson Contoso 大学示例 web 应用程序演示如何使用 Entity Framework Core 和 Visual Studio 创建 ...

  3. kafka源码分析(二)Metadata的数据结构与读取、更新策略

    一.基本思路 异步发送的基本思路就是:send的时候,KafkaProducer把消息放到本地的消息队列RecordAccumulator,然后一个后台线程Sender不断循环,把消息发给Kafka集 ...

  4. 如何使用Python创建,读取,更新和搜索Excel文件

    This article will show in detail how to work with Excel files and how to modify specific data with P ...

  5. ArcGIS Engine效率探究——要素的添加和删除、属性的读取和更新(转载)

    转自:http://blog.csdn.net/freewaywalker/article/details/23703863 1. 要素的添加 ArcGIS Engine中,主要有两个方法用于要素的添 ...

  6. python3 csv读写_在python3中读取、更新和写入更新的CSV文件

    我正在创建一个应用程序来本质上充当一个资产数据库,我试图打开一个CSV文件,读取值并相应地更新它们.我看到很多关于如何读写CSV文件的教程,但是我找不到一个详细介绍如何迭代CSV文件和更新单个值的教程 ...

  7. SharePoint 2010 SP1更新发布

    前几天微软SharePoint产品组正式发布了产品的SP1,中文版下载地址如下: 1.SharePoint Foundation 2010 Service Pack (KB2460058) 2.Mic ...

  8. python导入excel数据-python + Excel数据读取(更新)

    data.xlsx 数据如下: import xlrd #1.读取Excel数据 # table = xlrd.open_workbook("data.xlsx","r& ...

  9. python已停止工作appcrash_Python已经停止在Windows中工作(APPCRASH),使用GDAL读取和更新shapefile...

    我有一个复杂的程序,由许多Python脚本组成,它使用GDAL打开Esri shapefile,执行各种计算,并更新shapefile属性表.在 对于一些shapefile来说,它工作得非常好.对于其 ...

最新文章

  1. C++类构造函数初始化列表
  2. Node_exporter+Prometheus+Grafana 快速实现Linux系统性能数据提取、存储和可视化展示
  3. 【Android 组件化】路由组件 ( 页面跳转参数依赖注入 )
  4. IntelliJ IDEA使用(一):创建maven web项目
  5. 它有什么本事,能成为Apache基金会项目?阿里移动前端开源框架Weex揭秘 移动开发...
  6. Docker的安装及操作
  7. can总线学习(一)——初识can总线
  8. C语言 底层IO lseek
  9. vSphere vsan 6.5部署之一VCSA6.5安装
  10. MySQL中的DATE_SUB()函数和DATE_ADD()函数
  11. 动态内存分配(malloc函数)
  12. MATLAB中的概率函数
  13. 64 串口测速工具及实验
  14. selenium启动chrome时Proxy server需要验证用户
  15. win10简单方法安装杜比v4音效!win10 1909适用!
  16. php kingeditor 相对路径,kindeditor上传图片生成绝对地址
  17. 【Angular中的RxJS】- Subject 分类介绍
  18. Spring @Value(#{})和@Value(${})
  19. 怎样低成本的实现网页在移动端的适配
  20. python写一个简单的12306抢票

热门文章

  1. Unity实现Image图片显示视频 、灵活配置控制视频播放(视频格式为MovieTexture)
  2. Java Web eclipse中连接到mysql数据库
  3. linux下编译zbar64位,linux 编译zbar
  4. HISI_3516_vpss
  5. 杨彦兵博士|相机光通信简介
  6. 软件定义网络笔记(PART 1)
  7. Skr-Eric的HTML课堂(二)——HTML的列表标签和图片与超链接
  8. PHP CLI模式下的多进程应用
  9. Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=404, reply-text=
  10. ffplay使用sonic实现倍速播放