博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sharepoint
阅读量:4591 次
发布时间:2019-06-09

本文共 5575 字,大约阅读时间需要 18 分钟。

1.介绍

客户端模型是SharePoint 2010才提供的,可以更灵活的在任何客户端设备中操作SharePoint对象,在2007版本中没有客户端模型,2010中有三种客户端模型JavaScript,SilverLight,.NET Managed。下面是对比情况:

 

     

 

2.原理

当我们使用客户端模型访问SharePoint 2010服务器对象的时候,请求首先会被打包成XML格式的SharePoint对象模型,然后在由客户端发送到服务器端,在服务器端调用服务器端的对象模型,。然后得到反应结果以JSON

格式发给客户端对象模型,客户端模型在解析得到的结果,展现给前端,如下图:

3.客户端模型对象

服务器端 客户端 Javascript
Microsoft.SharePoint.SPContext Microsoft.SharePoint.Client.ClientContext SP.ClientContext
Microsoft.SharePoint.SPSite Microsoft.SharePoint.Client.Site SP.Site
Microsoft.SharePoint.SPWeb Microsoft.SharePoint.Client.Web SP.Web
Microsoft.SharePoint.SPList Microsoft.SharePoint.Client.List SP.List
Microsoft.SharePoint.SPListItem Microsoft.SharePoint.Client.ListItem SP.ListItem
Microsoft.SharePoint.SPField Microsoft.SharePoint.Client.Field SP.Field

4.一些例子代码

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net;namespace OM{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender, EventArgs e)        {            Cursor old = this.Cursor;            this.Cursor = Cursors.WaitCursor;            Microsoft.SharePoint.Client.ClientContext clientContext = new Microsoft.SharePoint.Client.ClientContext("http://moss2010/sites/test");            NetworkCredential nwc = CredentialCache.DefaultNetworkCredentials;            clientContext.Credentials = nwc;            Microsoft.SharePoint.Client.Web web = clientContext.Web;            clientContext.Load(web);            clientContext.ExecuteQuery();            this.lblSiteTitle.Text = web.Title;            this.Cursor = old;        }        private void button2_Click(object sender, EventArgs e)        {            Cursor old = this.Cursor;            this.Cursor = Cursors.WaitCursor;            Microsoft.SharePoint.Client.ClientContext clientContext = new Microsoft.SharePoint.Client.ClientContext("http://moss2010/sites/test");            NetworkCredential nwc = CredentialCache.DefaultNetworkCredentials;            clientContext.Credentials = nwc;            Microsoft.SharePoint.Client.Web web = clientContext.Web;            var query = from list                        in clientContext.Web.Lists                        where list.Title == "SharePoint Team Members"                        select list;            var result = clientContext.LoadQuery(query);            clientContext.ExecuteQuery();            Microsoft.SharePoint.Client.List listMember = result.SingleOrDefault
(); Microsoft.SharePoint.Client.CamlQuery caml = new Microsoft.SharePoint.Client.CamlQuery(); caml.ViewXml = @"
"; Microsoft.SharePoint.Client.ListItemCollection listItems = listMember.GetItems(caml); clientContext.Load(listItems); clientContext.ExecuteQuery(); List
allDatas = new List
(); foreach (Microsoft.SharePoint.Client.ListItem item in listItems) { allDatas.Add(new Employee(item["Title"], item["Age"], item["Sex"])); } dataGridView1.DataSource = allDatas; this.Cursor = old; } private void button3_Click(object sender, EventArgs e) { Microsoft.SharePoint.Client.ClientContext clientContext = new Microsoft.SharePoint.Client.ClientContext("http://moss2010/sites/test"); NetworkCredential nwc = CredentialCache.DefaultNetworkCredentials; clientContext.Credentials = nwc; Microsoft.SharePoint.Client.Web web = clientContext.Web; var query = from list in clientContext.Web.Lists where list.Title == "SharePoint Team Members" select list; var result = clientContext.LoadQuery(query); clientContext.ExecuteQuery(); Microsoft.SharePoint.Client.List listMember = result.SingleOrDefault
(); Microsoft.SharePoint.Client.CamlQuery caml = new Microsoft.SharePoint.Client.CamlQuery(); caml.ViewXml = @"
" + tbxInput.Text + "
"; Microsoft.SharePoint.Client.ListItemCollection listItems = listMember.GetItems(caml); clientContext.Load(listItems); clientContext.ExecuteQuery(); this.lblOutput.Text = listItems[0].FieldValues["Title"].ToString(); this.Cursor = old; } } public class Employee { public Employee(object title, object age, object sex) { this.Age = age; this.Sex = sex; this.Title = title; } public object Title { get; set; } public object Age { get; set; } public object Sex { get; set; } }}

 

ClientContext clientContext = new ClientContext("http://servername/");clientContext.ExecutingWebRequest += new EventHandler
(clientContext_ExecutingWebRequest);Web site = clientContext.Web;clientContext.Load(site);clientContext.ExecuteQuery();static void clientContext_ExecutingWebRequest(object sender, WebRequestEventArgs e){ e.WebRequestExecutor.WebRequest.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");}

 

Uri uri = new Uri("http://tempuri.org/");ICredentials credentials = CredentialCache.DefaultCredentials;NetworkCredential credential = credentials.GetCredential(uri, "Basic");

 

转载于:https://www.cnblogs.com/MarchThree/p/3728872.html

你可能感兴趣的文章
JAVA array,map 转 json 字符串
查看>>
2017-12-27练习
查看>>
NET设计规范(二) 命名规范
查看>>
VMware 9.0.1安装Mac OS X Mountain Lion 10.8.2
查看>>
SSL延迟
查看>>
android新手关于左右滑动的问题,布局把<android.support.v4.view.ViewPager/><ImageView/> 放在上面就不行了。...
查看>>
深入理解DIP、IoC、DI以及IoC容器
查看>>
赋值文件
查看>>
Vue 数组 字典 template v-for 的使用
查看>>
蓝牙模块选择经验谈
查看>>
java中==和equals
查看>>
CCActionPageTurn3D
查看>>
python random
查看>>
esp32-智能语音-cli(调试交互命令)
查看>>
netty与MQ使用心得
查看>>
关于dl dt dd 文字过长换行在移动端显示对齐的探讨总结
查看>>
swoolefy PHP的异步、并行、高性能网络通信引擎内置了Http/WebSocket服务器端/客户端...
查看>>
Python学习笔记
查看>>
unshift()与shift()
查看>>
使用 NPOI 、aspose实现execl模板公式计算
查看>>