Я использую Visual Studio для Ma c и пытаюсь подключиться к SharePoint, чтобы получить некоторые данные через консольное приложение. Но по какой-то причине я получаю System.TypeInitializationException. Пожалуйста, помогите мне с тем же. Я прилагаю код для дальнейшего использования.
using System;
using System.Security;
using Microsoft.Graph;
using Microsoft.SharePoint.Client;
namespace PITracker_Teams_Automation
{
class Program
{
static void Main(string[] args)
{
string userName = "email account";
Console.WriteLine("Enter your password.");
SecureString password = GetPassword();
// ClienContext - Get the context for the SharePoint Online Site
// SharePoint site URL - https://c986.sharepoint.com
using (var clientContext = new ClientContext("https://organizationName.sharepoint.com/_layouts/15/sharepoint.aspx"))
{
//clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
// SharePoint Online Credentials
clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
// Get the SharePoint web
Web web = clientContext.Web;
// Load the Web properties
clientContext.Load(web);
// Execute the query to the server.
clientContext.ExecuteQuery();
// Web properties - Display the Title and URL for the web
Console.WriteLine("Title: " + web.Title + "; URL: " + web.Url);
Console.ReadLine();
}
}
private static SecureString GetPassword()
{
ConsoleKeyInfo info;
//Get the user's password as a SecureString
SecureString securePassword = new SecureString();
do
{
info = Console.ReadKey(true);
if (info.Key != ConsoleKey.Enter)
{
securePassword.AppendChar(info.KeyChar);
}
}
while (info.Key != ConsoleKey.Enter);
return securePassword;
}
}
}
'' '