private void button1_Click(object sender, EventArgs e) { this.Enabled = false; // attempt to login with user's credentials using (ClientContextCreator contextCreator = new ClientContextCreator(Properties.Settings.Default.SiteURL, this.textBox1.Text, this.textBox2.Text)) { StatusForm statusForm = new StatusForm(); // rig the cancel button statusForm.button1.Click += new EventHandler(delegate(object s, EventArgs a) { // cancel the login process contextCreator.CancelLogin(); }); ClientContext clientContext = contextCreator.Login(); // if it fails then re-prompt user if (clientContext == null) { statusForm.Close(); this.Enabled = true; return; } // if it succeeds then open main window and pass authenticated Context to it MessageBox.Show("Logged in!"); // if checkbox is set then save username and password before opening window } }
static void Main(string[] args) { //Application.Run(new LoginForm()); using (ClientContextCreator contextCreator = new ClientContextCreator(Properties.Settings.Default.SiteURL, " ", " ")) //using (ClientContext clientContext = ClaimClientContext.GetAuthenticatedContext(Properties.Settings.Default.SiteURL, " ", " ")) { using (ClientContext clientContext = contextCreator.Login()) { if (clientContext != null) { Web site = clientContext.Web; clientContext.Load(site); clientContext.ExecuteQuery(); ListCollection lists = site.Lists; clientContext.Load(lists); clientContext.ExecuteQuery(); Console.WriteLine("The current site contains the following folders:\n\n"); foreach (List list in lists) { Console.WriteLine(list.Title); } } else { Console.WriteLine("Bad username or password"); } } } Console.ReadKey(); }