public List <SharePointItem> SiteCollections() { List <SharePointItem> results = new List <SharePointItem>(); SPOSitePropertiesEnumerable prop = null; string tenantAdminURL = @"https://dddevops-admin.sharepoint.com/"; using (ClientContext context = new ClientContext(tenantAdminURL)) { SecureString securePassword = new SecureString(); foreach (char c in password.ToCharArray()) { securePassword.AppendChar(c); } context.Credentials = new SharePointOnlineCredentials(username, securePassword); Tenant tenant = new Tenant(context); prop = tenant.GetSiteProperties(0, true); context.Load(prop); context.ExecuteQuery(); foreach (SiteProperties sp in prop) { SharePointItem item = new SharePointItem() { Title = sp.Title, URL = sp.Url }; results.Add(item); } } return(results); }
private void DisplayItem(SharePointItem listitem, TreeNodeCollection treeNodeCollection) { TreeNode itemnode = new TreeNode(listitem.Title); itemnode.Tag = listitem; itemnode.ImageKey = "SPItem"; itemnode.SelectedImageKey = "SPItem"; treeNodeCollection.Add(itemnode); foreach(SharePointItem childItem in listitem.ChildItems) { DisplayItem(childItem, itemnode.Nodes); } }
private void DisplayItem(SharePointItem listitem, TreeNodeCollection treeNodeCollection) { TreeNode itemnode = new TreeNode(listitem.Title); itemnode.Tag = listitem; itemnode.ImageKey = "SPItem"; itemnode.SelectedImageKey = "SPItem"; treeNodeCollection.Add(itemnode); foreach (SharePointItem childItem in listitem.ChildItems) { DisplayItem(childItem, itemnode.Nodes); } }
public GetDocumentsListItemsResponse GetDocumentsListItems(GetDocumentsListItemsRequest request) { using (ClientContext context = SignIn(request.ServerProperties)) { try { Microsoft.SharePoint.Client.List root = context.Web.Lists.GetByTitle(SharedDocumentsList); CamlQuery camlQuery = new CamlQuery(); if (request.FolderUri != null && !string.IsNullOrWhiteSpace(request.FolderUri.ToString())) { camlQuery.FolderServerRelativeUrl = GetCombinedPath(context, root, request.FolderUri.ToString()); } var queryItems = root.GetItems(camlQuery); // We must specify what properties we want to load context.Load(queryItems, a => a.Include( b => b.DisplayName, b => b.FileSystemObjectType )); context.ExecuteQuery(); SharePointItem[] items = new SharePointItem[queryItems.Count]; for (int i = 0; i < queryItems.Count; i++) { ListItem queryItem = queryItems[i]; SharePointItem item = new SharePointItem(); item.Type = queryItem.FileSystemObjectType; // Sometimes, the Sharepoint directory may not have a "File" or "Folder" column. try { if (item.Type == FileSystemObjectType.File) { context.Load(queryItem, a => a.File.Name); context.ExecuteQuery(); item.Name = queryItem.File.Name; } else if (item.Type == FileSystemObjectType.Folder) { context.Load(queryItem, a => a.Folder.Name); context.ExecuteQuery(); item.Name = queryItem.Folder.Name; } } catch { // Column must not exist } // If we failed above, use the potentially-less-accurate "Display Name" if (string.IsNullOrEmpty(item.Name)) { item.Name = queryItem.DisplayName; } items[i] = item; } return(new GetDocumentsListItemsResponse { Items = items }); } catch { throw; } } }