当前位置:网站首页>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
更多文章请扫码关注公众号,有问题的小伙伴也可以在公众号上提出哦。

边栏推荐
- Shanzhai coin Shib has a US $548.6 million stake in eth whale's portfolio - traders should be on guard
- 7 月 28 日 ENS/USD 价值预测:ENS 吸引巨额利润
- 突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘
- Hcia-r & s self use notes (24) ACL
- “山东大学移动互联网开发技术教学网站建设”项目实训日志七
- Qtcreator+cmake compiler settings
- How can Plato obtain premium income through elephant swap in a bear market?
- QT layout management -- Part stretch principle and sizepolicy
- 改哭了,终于解决了Cannot read properties of undefined (reading ‘parseComponent‘)
- OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程
猜你喜欢

Common prompt pop-up box of uniapp

熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊

性能对比|FASS iSCSI vs NVMe/TCP

Gluster集群管理小分析

MOVE PROTOCOL全球健康宣言,将健康运动进行到底

Wechat applet - component parameter transmission, state management

Masscan使用教程.

DAY4:SQL Sever 简单使用

Fantom (FTM) prices will soar by 20% in the next few days

Read and understand move2earn project - move
随机推荐
7 月 28 日 ENS/USD 价值预测:ENS 吸引巨额利润
机器学习让文字识别更简单:Kotlin+MVVM+华为ML Kit
Refresh, swagger UI theme changes
获取水仙花数
使用Qss设置窗体样式
Wechat applet - screen height
SQL修复重复数据
Print out all prime numbers between 1-100
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
DAY6:利用 PHP 编写登陆页面
Day14: upload labs customs clearance tutorial
Merge the same items in the same column in table
量化开发必掌握的30个知识点【什么是分笔逐笔数据】?
Go|Gin 快速使用Swagger
QT layout management -- Part stretch principle and sizepolicy
Common prompt pop-up box of uniapp
Selection options of uniapp components (such as package selection)
北京宝德&TaoCloud共建信创之路
Strategic cooperation with many institutions shows the strength of the leading company of platofarm yuancosmos
The completely decentralized programming mode does not need servers or IP, just like a aimless network extending everywhere