/// <summary> /// This dynamically creates the loads the webs /// web service and gets the web collection for the /// current site. Once this is done, you can iterate /// through the collection and retrieve information /// about a single site through the GetWeb service. /// </summary> /// <remarks>Needs to be redone to get the sites from /// something other than the Sites list as this doesn't /// guarantee that all sites are registered this way.</remarks> public void LoadWebCollection() { Webs ws = NewWebsWebService(); try { XmlNode root = ws.GetWebCollection(); XmlNodeList siteList = root.SelectNodes("*"); foreach(XmlNode node in siteList) { string newSiteName = node.Attributes["Title"].Value; string newSiteUrl = node.Attributes["Url"].Value; SharePointSite spSite = new SharePointSite(newSiteName, newSiteUrl); spSite.Credentials = Credentials; subSites.Add(spSite); } } catch (WebException ex) { Console.WriteLine(ex.Message); } catch (SoapException sex) { Console.WriteLine(sex.Message); } }
/// <summary> /// This loads the top level sites based on the site /// list obtained through the SiteDirectory and the list /// web service. This creates a new SharePointSite object /// which then in turn recursively loads up any subsites /// it owns. /// </summary> /// <remarks> /// NOTE: This uses the Sites list from the SiteDirectory /// so it assumes all sites are recorded through this so this has /// a heavy dependancy on how your sites are recorded. If you want /// to get the raw list you can use <see cref="LoadWebCollection"/> /// as this will get everything. The only thing with that method is /// that you'll get sitenames like C1, C2, etc. when you do it at /// the portal level. /// </remarks> public void LoadSiteCollection() { Lists ws = NewSiteDirectoryListsWebService(); XmlNode lists = ws.GetListCollection(); foreach(XmlNode list in lists) { string listName = list.Attributes["Title"].Value; if(listName.ToUpper() == "SITES") { // Get the list data from the site list string rowLimit = Convert.ToString(1000); XmlNode nodListItems = ws.GetListItems(listName, "", null, null, rowLimit, null); if(nodListItems.HasChildNodes) { // Rows are members of the second child node XmlNode nodRows = nodListItems.ChildNodes[1]; if(nodRows.HasChildNodes) { foreach(XmlNode node in nodRows.ChildNodes) { if(node.NodeType == XmlNodeType.Element) { string name = node.Attributes["ows_SiteTitle"].Value; string url = CreateFQDN(node.Attributes["ows_SiteURL"].Value); SharePointSite site = new SharePointSite(name, url); site.Credentials = Credentials; siteCollection.Add(site); } } } } } } }
/// <summary> /// This adds the child sites to a list based on a filter. /// This allows us to recursively add all children regardless /// of the parent type. /// </summary> /// <param name="parentSite"></param> /// <param name="filter"></param> /// <param name="list"></param> public void AddChildSitesToList(SharePointSite parentSite, string filter, ArrayList list) { foreach(SharePointSite site in parentSite.SubSites) { list.Add(site); if(site.SubSites.Count > 0) AddChildSitesToList(site, filter, list); } }
/// <summary> /// Loads the web collection for a given SharePoint server or /// top level site collection. If used on a portal server, you'll /// get all kinds of values like C1, C2, etc. for all areas. /// </summary> public void LoadWebCollection() { Webs ws = NewWebsWebService(); XmlNode xml = ws.GetWebCollection(); foreach (XmlNode xmlNode in xml) { string name = xmlNode.Attributes["Title"].Value; string url = CreateFQDN(xmlNode.Attributes["Url"].Value); SharePointSite web = new SharePointSite(name, url); web.Credentials = Credentials; webCollection.Add(web); } }