Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Security;
- using Microsoft.SharePoint.Client;
- namespace SharePointOnlineAuthTest
- {
- internal class Program
- {
- private static void Main(string[] args)
- {
- const string serverRelativeUrl = "/site";
- const string userName = "user@vccqa.onmicrosoft.com";
- const string password = "password";
- using (var ctx = GetSharePointOnlineContext(serverRelativeUrl, userName, password))
- {
- var web = ctx.Web;
- ctx.Load(web);
- ctx.ExecuteQuery();
- Console.WriteLine(web.Title);
- Console.ReadLine();
- }
- }
- private static ClientContext GetSharePointOnlineContext(string serverRelativeUrl, string userName, string password)
- {
- var baseUri = new Uri("https://vccqa.sharepoint.com/");
- var siteUri = new Uri(baseUri, serverRelativeUrl);
- var securePassword = new SecureString();
- foreach (var c in password) securePassword.AppendChar(c);
- return new ClientContext(siteUri) {Credentials = new SharePointOnlineCredentials(userName, securePassword)};
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement