visual-studio-2015 - microsoft.sharepoint.client.dll 中发生了 system.net.webException 类型的未处理异常
问题描述
我正在使用visual studio 2015......我需要通过visual stuido连接到sharepoint。
我在 vs 2015 中添加了 microsoft sharepoint 在线 csom 参考
但由于错误我无法执行代码.....
解决方案
如果您使用的是 SharePoint Online,请使用 SharePointOnlineCredentials 类将凭据设置为 ClientContext 对象,以下是供您参考的代码片段:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.SharePoint.Client;
namespace CSOMWinApp
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string password = "xxxxxx";
string account = "user@Tenant.onmicrosoft.com";
var secret = new System.Security.SecureString();
foreach (char c in password)
{
secret.AppendChar(c);
}
var credentials = new SharePointOnlineCredentials(account, secret);
using (ClientContext ctx = new ClientContext("https://zheguo.sharepoint.com/sites/dev"))
{
ctx.Credentials = new SharePointOnlineCredentials(account, secret);
Web web = ctx.Web;
ctx.Load(web);
ctx.ExecuteQuery();
}
}
}
}
参考:
推荐阅读
- python - 用字典替换熊猫数据框无值
- lucene - Lucene 索引结构问题
- bash - ~/.bashrc 上的问题,写入的文件 PATH 不正确
- css - 如何在基于 css 模块的反应应用程序中使用已经严格的 css 常规工作表?
- google-cloud-build - 在 docker build 中注入服务帐户 json
- java - Java Swing 在等待方法时在 actionPerformed 函数中更改 UI 两次
- postgresql - 在没有联结表的情况下查询多对多关系
- linux - 列出 Linux 中名称中不包含数字的文件
- python - AttributeError:“NoneType”对象在带有 tf.keras.models.load_model 的 Chaquopy 中没有属性“predict”
- javascript - Onclick 类切换未触发