c# - 在 C# 代码中使用 Sharepoint 365 现代体验获取运行时错误
问题描述
我正在尝试访问 SharePoint 网站中的列表,我正在使用具有现代体验的 Sharepoint 365。
我的问题是我上线超时错误
clientContext.ExecuteQuery();
这是我的代码:
using (ClientContext clientContext = new ClientContext("https:siteurl"))
{
SecureString passWord = new SecureString();
foreach (char c in "mypwd".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("myuser", passWord);
Web web = clientContext.Web;
// Retrieve all lists from the server.
// For each list, retrieve Title and Id.
clientContext.Load(web.Lists,
lists => lists.Include(list => list.Title,
list => list.Id));
// Execute query.
clientContext.ExecuteQuery();
// Enumerate the web.Lists.
foreach (List list in web.Lists)
{
label1.Text = label1.Text + ", " + list.Title;
}
}
解决方案
在代码中添加clientContext.RequestTimeout = -1,下面的代码供大家参考。
using (ClientContext clientContext = new ClientContext("https:siteurl"))
{
SecureString passWord = new SecureString();
foreach (char c in "mypwd".ToCharArray()) passWord.AppendChar(c);
clientContext.Credentials = new SharePointOnlineCredentials("myuser", passWord);
clientContext.RequestTimeout = -1;
Web web = clientContext.Web;
// Retrieve all lists from the server.
// For each list, retrieve Title and Id.
clientContext.Load(web.Lists,
lists => lists.Include(list => list.Title,
list => list.Id));
// Execute query.
clientContext.ExecuteQuery();
// Enumerate the web.Lists.
foreach (List list in web.Lists)
{
label1.Text = label1.Text + ", " + list.Title;
}
}
推荐阅读
- c++ - 一旦对象设置为null,用于声明对象堆大小的变量被设置为null?
- android - android apk jenkins 的存档工件
- python - Python:编写识别对象并对其进行计数的代码
- php - Unix 时间到第二天的时间戳
- android - 使用默认视频意图 ACTION_VIDEO_CAPTURE 录制不带声音的视频或在视频录制后删除声音,例如快速聊天
- python - Pyspark 在计算一列的偏度时不显示任何内容
- listview - 如何在颤动中准确使用 ListWheelScrollView?
- mailgun - 可以使用接收者变量有条件地渲染部分吗
- windows - WSL.exe 和 ubuntu.exe 不同
- godot - 如何使用实时服务器 ip 连接两个设备,而不是 Godot 3.1 中的本地主机?