c# - 读取列表:远程服务器返回错误:(401)未授权
问题描述
我正在尝试使用 ac# app 在线阅读项目中的列表所以这里是我的代码:
ClientContext clientContext = new ClientContext(client.activeProfileUrl.ToString());
List announcementsList = clientContext.Web.Lists.GetByTitle("GetUrl");
CamlQuery query = CamlQuery.CreateAllItemsQuery(100);
ListItemCollection items = announcementsList.GetItems(query);
clientContext.Load(items);
clientContext.ExecuteQuery();
foreach (ListItem listItem in items)
{
logUtil.writeLine("Title: " + listItem["Title"]);
}
所以我的 client.activeprofile 返回我的用户连接的环境的 url(它运行良好)但是当我到达线路时:clientContext.ExecuteQuery();
我收到错误 401
知道我应该做什么吗?
谢谢
解决方案
I think you must set credentials for ClientContext.
Please see this link:
https://www.c-sharpcorner.com/article/connect-to-sharepoint-2013-online-using-csom-with-console-ap/
I think it will be what you want.
clientContext.Credentials = new SharePointOnlineCredentials(userName,password);
推荐阅读
- .net - 使字符串在 .NET 应用程序中持久化
- angular - IdentityServer4、Angular 和 .NET CORE Api
- reactjs - 如果我使用 mapStateToProps,输入属性不会改变
- apache-spark - Elasticsearch Spark 解析问题 - 无法解析字段 [Y] 的值 [X]
- javascript - 如果子项包含某个文本/字符串,如何隐藏父 div?
- java - MySQL内部连接错误:在执行查询期间检测到为空。主键不能包含 null
- php - phpMyadmin error "continue" targeting switch is equivalent to "break"
- java - Spring Rest Hibernate 创建嵌套对象
- android - 如何修复此错误 retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall 无法转换为 com.example.test.dto.User
- android - kotlin 中数据绑定的好处?