[置顶] C# 连接 SharepointOnline WebService
2017-07-26 16:42
495 查看
使用Sharepoint Client对象模型进行数据读取:
其实最重要的验证身份凭据,验证方式和WebService的有点不同:
用的是:SharePointOnlineCredentials
ClientContext clientContext = new ClientContext(ConfigHelper.GetConfigStr("SharepointOnlineURL")); string strPassWord = ConfigHelper.GetConfigStr("SharepointOnlinePW"); char[] pChar = strPassWord.ToCharArray(); SecureString password = new SecureString(); foreach (char c in pChar) { password.AppendChar(c); } clientContext.Credentials = new SharePointOnlineCredentials(ConfigHelper.GetConfigStr("SharepointOnlineUser"), password); List a = clientContext.Web.Lists.GetByTitle("邮件分发定义"); CamlQuery camlQuery = new CamlQuery(); camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name=\"UseJob\"></FieldRef><Value Type=\"Text\">" + JobName + "</Value></Eq></Where></Query></View>"; Microsoft.SharePoint.Client.ListItemCollection Listitems = a.GetItems(camlQuery); clientContext.Load( Listitems, items => items .Include( item => item["ReportName"], item => item["Addressee"], item => item["UseJob"], item => item["ExcelName"], item => item["AccountNumber"] )); clientContext.Load(Listitems); clientContext.ExecuteQuery(); DataTable dt = new DataTable(); dt.Columns.Add("ReportName", Type.GetType("System.String")); dt.Columns.Add("Addressee", Type.GetType("System.String")); dt.Columns.Add("UseJob", Type.GetType("System.String")); dt.Columns.Add("ExcelName", Type.GetType("System.String")); dt.Columns.Add("AccountNumber", Type.GetType("System.String")); foreach (Microsoft.SharePoint.Client.ListItem listItem in Listitems) { DataRow newRow; newRow = dt.NewRow(); newRow["ReportName"] = listItem["ReportName"].ToString(); newRow["Addressee"] = listItem["Addressee"].ToString(); newRow["UseJob"] = listItem["UseJob"].ToString(); newRow["ExcelName"] = listItem["ExcelName"].ToString(); newRow["AccountNumber"] = listItem["ExcelName"].ToString(); dt.Rows.Add(newRow); } string result = JsonConvert.SerializeObject(dt); return result;
其实最重要的验证身份凭据,验证方式和WebService的有点不同:
clientContext.Credentials = new SharePointOnlineCredentials(ConfigHelper.GetConfigStr("SharepointOnlineUser"), password);
用的是:SharePointOnlineCredentials
相关文章推荐
- Connecting SharePoint Online and CRM Online using BCS - 2013 Edition-SP online连接CRM online
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第13章节--使用业务连接服务创建业务线解决方式
- 微软在SharePoint Online里面去掉了Public Site功能
- c# 连接mysql并webservice数据
- 安装使用SharePoint Online Management Shell的时候出现的问题
- Installing Office Online Server for SharePoint 2016
- SharePoint Server 2016 - Configure Office Online Server
- SharePoint Designer 2013 连接 Office 365 必需安装2个SP
- 在启用sharepoint portal server 2003的SSO时,提示“无法连接到数据库服务器,请检查配置账户的权利”的问题的解决方法
- C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第13章节--使用业务连接服务创建业务线解决方式 创建启用BCS的业务解决方式
- SharePoint Online 创建资产库
- 转:C# 对sharepoint 列表的一些基本操作,包括添加/删除/查询/上传文件给sharepoint list添加数据
- SharePoint Online 创建和使用栏
- Step by step configuration of Outgoing Emails from SharePoint to Microsoft Online
- Microsoft SharePoint: Building Office 2007 Solutions in C# 2005
- 走进Sharepoint2013至Sharepoint Online迁移②
- SharePoint Online 设置网站集
- Sharepoint online 创建模板与使用模板
- SharePoint Online 创建和使用视图