Необработанное исключение типа system. net .webException произошло в microsoft.sharepoint.client.dll - PullRequest
0 голосов
/ 11 апреля 2020

нажмите здесь, чтобы посмотреть фотографию

Я использую Visual Studio 2015 ...... Мне нужно подключиться к sharepoint с помощью Visual Stuido.

I добавлена ​​ссылка на csom для Microsoft sharepoint Online в версии 2015

, но я не могу выполнить код из-за ошибки .....

1 Ответ

0 голосов
/ 13 апреля 2020

Если вы используете 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();
            }
        }
    }
}

Ссылка:

Консольное приложение SharePoint Online с csom

...