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

边栏推荐
- Plato Farm有望通过Elephant Swap,进一步向外拓展生态
- Crypto giants all in metauniverse, and platofarm may break through
- 全闪分布式,如何深度性能POC?
- Hcia-r & s self use notes (25) NAT technical background, NAT type and configuration
- [electronic circuit] how to select ADC chip
- 打印出1-100之间的所有质数
- Strategic cooperation with many institutions shows the strength of the leading company of platofarm yuancosmos
- [untitled]
- Record the SQL injection vulnerability of XX company
- Laravel service container (Application of context binding)
猜你喜欢

农村品牌建设给年轻人的一些机会

马斯克推崇的柏拉图式元宇宙,PlatoFarm早已验证出答案

突破硬件瓶颈(一):Intel体系架构的发展与瓶颈挖掘

Fantom (FTM) surged 45% before the FOMC meeting

Go|Gin 快速使用Swagger

极致通缩和永动机模型,将推动 PlatoFarm 爆发

使用Qss设置窗体样式

Go|gin quickly use swagger

Starfish OS:以现实为纽带,打造元宇宙新范式

Shanzhai coin Shib has a US $548.6 million stake in eth whale's portfolio - traders should be on guard
随机推荐
MySQL decompressed version windows installation
量化开发必掌握的30个知识点【什么是Level-2数据】
Laravel service container (Application of context binding)
Read and understand move2earn project - move
Summary of knowledge points related to forms and forms
What is wapiti and how to use it
Masscan使用教程.
Gluster集群管理小分析
PHP如何生成二维码?
Qtcreator+cmake compiler settings
The completely decentralized programming mode does not need servers or IP, just like a aimless network extending everywhere
Go|gin quickly use swagger
Build msys2 environment with win10
Wechat applet - component parameter transmission, state management
Selection options of uniapp components (such as package selection)
Win10 搭建MSYS2环境
新手入门:手把手从PHP环境到ThinkPHP6框架下载
Wechat applet - screen height
“山东大学移动互联网开发技术教学网站建设”项目实训日志六
麦当娜“Hellbent”购买130万美元的nft无聊猿,现在被认为太贵了