/// <summary> /// BackgroundWorker Work event: /// Retrive user info to retrive the SPO Site lists /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bw_Dowork(object sender, DoWorkEventArgs e) { //We try to connect to the SharePoint Online site and retrieve the libraries try { using (var ctx = new ClientContext(SiteUrl)) { SharePointOnlineCredentials credentials = new SharePointOnlineCredentials(UserName, PassWord); ctx.Credentials = credentials; Web web = ctx.Web; ctx.Load(web, w => w.ServerRelativeUrl); this.Context = ctx; SPOLogic Context = new SPOLogic(ctx); //We check if the SPO site is a OneDrive Url, and process accordingly if (SiteUrl.Contains("/personal/")) { List odlists = ctx.Web.Lists.GetByTitle("Documents"); ctx.Load(odlists); ctx.ExecuteQuery(); this.ODLibrary = odlists; } //Else we have a SPO Site Url, and process accordingly else { ListCollection lists = Context.getLists(); this.Lists = lists; } } } catch (Exception ex) { MessageBox.Show(ex.Message); bw.CancelAsync(); e.Cancel = true; } }