当前位置:网站首页>C# 连接 SharepointOnline WebService
C# 连接 SharepointOnline WebService
2022-07-29 05:20:00 【Denny辉】
使用Sharepoint Client对象模型进行数据读取:
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
更多文章请扫码关注公众号,有问题的小伙伴也可以在公众号上提出哦。

边栏推荐
- 大部分PHP程序员,都搞不懂如何安全代码部署
- 完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
- nmap是什么以及使用教程
- Wapiti是什么以及使用教程
- 深度学习的趣味app简单优化(适合新手)
- 与开源项目同步开发& CodeReview & Pull Request & fork怎么拉取原始仓库
- Laravel service container (inheritance and events)
- Go|Gin 快速使用Swagger
- Wechat applet change attribute value -setdata- bidirectional binding -model
- Novice introduction: download from PHP environment to thinkphp6 framework by hand
猜你喜欢

OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程

Windows下cmd窗口连接mysql并操作表

JDBC连接数据库详细步骤

新手入门:手把手从PHP环境到ThinkPHP6框架下载

365 day challenge leetcode 1000 questions - day 035 one question per day + two point search 13

IDEA使用JDBC连接MySQL数据库个人详细教程

Thinkphp6管道模式Pipeline使用

QPalette学习笔记

“山东大学移动互联网开发技术教学网站建设”项目实训日志七

如何 Pr 一个开源composer项目
随机推荐
大部分PHP程序员,都搞不懂如何安全代码部署
Crypto giants all in metauniverse, and platofarm may break through
Move protocol global health declaration, carry out the health campaign to the end
Sqlmap是什么以及使用方法
Under the bear market of encrypted assets, platofarm's strategy can still obtain stable income
Hcia-r & s self use notes (26) PPP
Masscan使用教程.
[typescript] type reduction (including type protection) and type predicate in typescript
Crypto巨头们ALL IN元宇宙,PlatoFarm或能突围
Selection options of uniapp components (such as package selection)
DAY6:利用 PHP 编写文件上传页面
深度学习的趣味app简单优化(适合新手)
加密资产熊市之下,PlatoFarm的策略玩法依旧能获得稳定收益
Wechat applet - component parameter transmission, state management
Masscan tutorial
完全去中心化的编程模式,不需要服务器,也不需要ip,就像一张漫无目的的网络、四处延伸
打印出1-100之间的所有质数
Qt布局管理--部件拉伸(Stretch)原理及大小策略(sizePolicy)
使用Qss设置窗体样式
dcat 批量操作弹窗及参数传递