private static void ConnectToSite() { Console.WriteLine("Please enter the URL to the SharePoint Site"); url = Console.ReadLine(); Console.WriteLine("Please enter the username"); username = Console.ReadLine(); Console.WriteLine("Please enter the password"); SecureString securepassword = getpassword(); clientContext = new ClientContext(url); password = new SecureString(); string charpassword = new NetworkCredential(string.Empty, securepassword).Password; foreach (char c in charpassword.ToCharArray()) password.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials(username, password); site = clientContext.Site; clientContext.Load(site); clientContext.ExecuteQuery(); siteRelativeUrl = site.ServerRelativeUrl; clientContext.Load(site.RootWeb); clientContext.ExecuteQuery(); Console.WriteLine(""); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Successfully connected to site at " + site.Url); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press any key to continue.."); Console.ReadLine(); }