Sharepoint Client Object Model 之 开发基于.NET的应用程序
来源:互联网 发布:计算机算法特点 编辑:程序博客网 时间:2024/06/16 08:58
前提:引用using Microsoft.SharePoint.Client;和using Microsoft.SharePoint.Client.Runtime两个类库
1、客户端Create a List
ListCreationInformation listCreationInfo = new ListCreationInformation(); listCreationInfo.Title = "Client API Test List"; listCreationInfo.TemplateType = (int)ListTemplateType.GenericList; List list = clientContext.Web.Lists.Add(listCreationInfo); // Add fields to the list. Field field1 = list.Fields.AddFieldAsXml( @"<Field Type='Choice' DisplayName='Category' Format='Dropdown'> <Default>Specification</Default> <CHOICES> <CHOICE>Specification</CHOICE> <CHOICE>Development</CHOICE> <CHOICE>Test</CHOICE> <CHOICE>Documentation</CHOICE> </CHOICES> </Field>", true, AddFieldOptions.DefaultValue); Field field2 = list.Fields.AddFieldAsXml( @"<Field Type='Number' DisplayName='Estimate'/>", true, AddFieldOptions.DefaultValue);clientContext.ExecuteQuery();
2、客户端Add ListItem
// Add some data. ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); ListItem listItem = list.AddItem(itemCreateInfo); listItem["Title"] = "Write specs for user interface."; listItem["Category"] = "Specification"; listItem["Estimate"] = "20"; listItem.Update(); listItem = list.AddItem(itemCreateInfo); listItem["Title"] = "Develop proof-of-concept."; listItem["Category"] = "Development"; listItem["Estimate"] = "42"; listItem.Update(); listItem = list.AddItem(itemCreateInfo); listItem["Title"] = "Write test plan for user interface."; listItem["Category"] = "Test"; listItem["Estimate"] = "16"; listItem.Update(); listItem = list.AddItem(itemCreateInfo); listItem["Title"] = "Validate SharePoint interaction."; listItem["Category"] = "Test"; listItem["Estimate"] = "18"; listItem.Update(); listItem = list.AddItem(itemCreateInfo); listItem["Title"] = "Develop user interface."; listItem["Category"] = "Development"; listItem["Estimate"] = "18"; listItem.Update(); clientContext.ExecuteQuery();
3、访问大型列表使用 ListItemCollectionPosition 属性进行分页的方法。
using System;using System.Linq;using Microsoft.SharePoint.Client;class Program{ static void Main() { ClientContext clientContext = new ClientContext("http://intranet.contoso.com"); List list = clientContext.Web.Lists .GetByTitle("Client API Test List"); // First, add 20 items to Client API Test List so that there are // enough records to show paging. ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation(); for (int i = 0; i < 20; i++) { ListItem listItem = list.AddItem(itemCreateInfo); listItem["Title"] = String.Format("New Item #{0}", i); listItem["Category"] = "Development"; listItem["Estimate"] = i; listItem.Update(); } clientContext.ExecuteQuery(); // This example shows paging through the list ten items at a time. // In a real-world scenario, you would want to limit a page to // 2000 items. ListItemCollectionPosition itemPosition = null; while (true) { CamlQuery camlQuery = new CamlQuery(); camlQuery.ListItemCollectionPosition = itemPosition; camlQuery.ViewXml = @"<View> <ViewFields> <FieldRef Name='Title'/> <FieldRef Name='Category'/> <FieldRef Name='Estimate'/> </ViewFields> <RowLimit>10</RowLimit> </View>"; ListItemCollection listItems = list.GetItems(camlQuery); clientContext.Load(listItems); clientContext.ExecuteQuery(); itemPosition = listItems.ListItemCollectionPosition; foreach (ListItem listItem in listItems) Console.WriteLine(" Item Title: {0}", listItem["Title"]); if (itemPosition == null) break; Console.WriteLine(itemPosition.PagingInfo); Console.WriteLine(); } }}
0 0
- Sharepoint Client Object Model 之 开发基于.NET的应用程序
- SharePoint 2010 Client Object Model-Client API
- Sharepoint的客户端对象模型(Client Object Model)(转)
- SharePoint 2010 Client Object Model - JavaScript(ECMAScript)
- 如何开启匿名访问SharePoint 2010里的Client Object Model
- SharePoint Client Object Model API 介绍以及工作原理解析
- Client Object Model
- 使用 SharePoint 2010 Client Object Model 修改用户Email(邮箱) 地址
- SharePoint 2013 客户端模型(Client Object Model) 调用搜索(Query Search)
- SharePoint Judge current user permission via Client Object Model about JavaScript
- SharePoint 2010 匿名用户调用Client Object Model访问列表项
- Get the metadata value using client object model from the sharepoint 2010
- 基于Grove的.NET应用程序开发提示
- 基于Grove的.NET应用程序开发提示
- 基于Grove的.NET应用程序开发提示
- Sharepoint Object Model程序的环境搭设问题
- SharePoint 2010 JavaScript Object Model中executeQueryAsync的递归调用
- 基于SharePoint 2010的控制台应用程序常见问题
- phpmailer 发送邮件笔记整理
- 多人联机射击游戏中的设计模式应用
- 我想写一个mud客户端
- 怎样在让chromium或者chrome在开启时就运用代理连接?
- const总结
- Sharepoint Client Object Model 之 开发基于.NET的应用程序
- Windows环境下Visual Studio 2012中搭建Cocos2d-x 3.1集成开发环境
- 【索引】Maintaining Interval Data::Exercises: Intermediate
- oracle学习 select操作
- libusb-win32介绍
- android客户端UI设计的一点体会
- 二叉树中的那些常见的面试题
- NGUI 弹出式多级菜单(自主研发)
- Linux脚本学习之路(0)