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

边栏推荐
- Laravel service container (inheritance and events)
- The difference between link and @import importing external styles
- Go|gin quickly use swagger
- 打印出1-100之间的所有质数
- 如何零代码制作深度学习的趣味app(适合新手)
- Merge the same items in the same column in table
- DAY4:SQL Sever 简单使用
- 麦当娜“Hellbent”购买130万美元的nft无聊猿,现在被认为太贵了
- Similarities and differences between REM and PX and EM
- Relationship between redrawing and reflow
猜你喜欢

量化开发必掌握的30个知识点【什么是Level-2数据】

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

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

Hcia-r & s self use notes (25) NAT technical background, NAT type and configuration

超简单集成HMS ML Kit 实现parental control

Crypto giants all in metauniverse, and platofarm may break through

Qt设置背景图片方法

Masscan tutorial

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

Sqlmap是什么以及使用方法
随机推荐
Countdown of the uniapp component (such as the countdown to reading the agreement and the countdown to completing learning)
DAY6:利用 PHP 编写登陆页面
Selection options of uniapp components (such as package selection)
PHP如何生成二维码?
Wechat applet - screen height
Day14: upload labs customs clearance tutorial
Common prompt pop-up box of uniapp
DAY14:Upload-labs 通关教程
麦当娜“Hellbent”购买130万美元的nft无聊猿,现在被认为太贵了
[JS question solution] questions 1-10 in JS of niuke.com
Some opportunities for young people in rural brand building
Laravel Swagger添加访问密码
What is wapiti and how to use it
Windows下cmd窗口连接mysql并操作表
量化开发必掌握的30个知识点【什么是分笔逐笔数据】?
Laravel swagger add access password
Hcia-r & s self use notes (27) comprehensive experiment
DAY4:MySQL 数据库的建立及简单实用
Differences between href and SRC
Fvuln-自动化web漏洞检测工具