当前位置:网站首页>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
更多文章请扫码关注公众号,有问题的小伙伴也可以在公众号上提出哦。
边栏推荐
- Record the SQL injection vulnerability of XX company
- 运动健康深入人心,MOVE PROTOCOL引领品质生活
- Starfish OS:以现实为纽带,打造元宇宙新范式
- 熊市慢慢,Bit.Store提供稳定Staking产品助你穿越牛熊
- Hcia-r & s self use notes (25) NAT technical background, NAT type and configuration
- WIN10 编译ffmpeg(包含ffplay)
- From starfish OS' continued deflationary consumption of SFO, the value of SFO in the long run
- Qt布局管理--部件拉伸(Stretch)原理及大小策略(sizePolicy)
- OpenAtom OpenHarmony分论坛圆满举办,生态与产业发展迈向新征程
- 北京宝德&TaoCloud共建信创之路
猜你喜欢
随机推荐
Laravel Swagger添加访问密码
“山东大学移动互联网开发技术教学网站建设”项目实训日志六
Build msys2 environment with win10
Seay源代码审计系统
Thinkphp6管道模式Pipeline使用
QT setting background image method
DAY13:文件上传漏洞
[typescript] in depth study of typescript functions
深度学习的趣味app简单优化(适合新手)
Plato farm is expected to further expand its ecosystem through elephant swap
浅谈分布式全闪存储自动化测试平台设计
加密资产熊市之下,PlatoFarm的策略玩法依旧能获得稳定收益
Laravel service container (Application of context binding)
Day14: upload labs customs clearance tutorial
Masscan使用教程.
SQL修复重复数据
php写一个购买全网最低价的纸尿裤
超简单集成HMS ML Kit 人脸检测实现可爱贴纸
Relationship between link and @import
Laravel swagger add access password