/// <summary> /// Returns a collection with webs from SharePoint. A web can contain other webs. To get all subwebs from a specified web, set the url in the Url property. /// </summary> /// <returns>Collection with webs.</returns> public SPWeb[] GetWebs() { Webs webs = new Webs(); webs.Credentials = Credentials; webs.PreAuthenticate = true; webs.Url = Url.ToString().Replace("lists.asmx", "webs.asmx"); webs.Proxy = GetProxy(); ServicePointManager.ServerCertificateValidationCallback += ((sender, certificate, chain, sslPolicyErrors) => true); XmlNode webscollection = null; webscollection = webs.GetWebCollection(); XmlDocument doc = new XmlDocument(); doc.LoadXml(webscollection.OuterXml); List <SPWeb> list = new List <SPWeb>(); foreach (XmlNode web in RunXPathQuery(doc, "//sp:Web")) { list.Add(new SPWeb(GetNodeAttribute(web.Attributes["Title"]), GetNodeAttribute(web.Attributes["Url"]), web)); } return(list.ToArray()); }
/// <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> /// Returns any sites under the Root sharepoint site /// </summary> /// <returns>List of sites under the specified site</returns> public IEnumerable <KeyValuePair <string, string> > GetSiteCollection() { _websWS.Url = _selectedSiteUrl + "_vti_bin/webs.asmx"; XElement siteCollection = XElement.Parse(_websWS.GetWebCollection().OuterXml); IEnumerable <KeyValuePair <string, string> > siteList = from sites in siteCollection.Elements() select new KeyValuePair <string, string>(sites.Attribute("Title").Value, sites.Attribute("Url").Value); return(siteList); }
/// <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); } }
public ReadOnlyCollection <SharepointWeb> GetSubWebs() { return(Utils.DoSharepointTask <ReadOnlyCollection <SharepointWeb> >(this.Identity, this.Id, null, true, Utils.MethodType.GetView, delegate { ReadOnlyCollection <SharepointWeb> result; using (Webs webs = new Webs(this.Uri.ToString())) { webs.Credentials = CredentialCache.DefaultCredentials; XmlNode webCollection = webs.GetWebCollection(); List <SharepointWeb> list = new List <SharepointWeb>(); foreach (object obj in webCollection.ChildNodes) { XmlNode xmlNode = (XmlNode)obj; list.Add(new SharepointWeb(xmlNode.Attributes["Title"].Value, new SharepointSiteId(xmlNode.Attributes["Url"].Value, UriFlags.Sharepoint))); } result = new ReadOnlyCollection <SharepointWeb>(list); } return result; })); }
private static void Recursive(WebRecord records) { Webs webs = new Webs(); webs.Url = records.Url + "/" + "_vti_bin/webs.asmx"; webs.Credentials = credential; //webs.CookieContainer = GetAuthCookies(); XmlNode subwebs = webs.GetWebCollection(); foreach (XmlNode node in subwebs.ChildNodes) { WebRecord web = new WebRecord() { Title = node.Attributes[0].Value, Url = node.Attributes[1].Value, LastModified = DateTime.MinValue.Year }; Lists lists = new Lists(); lists.Url = web.Url + "/_vti_bin/lists.asmx"; lists.Credentials = credential; //lists.CookieContainer = GetAuthCookies(); XmlNode list = lists.GetListCollection(); List <ListRecord> listRecordList = new List <ListRecord>(); foreach (XmlNode listnode in list.ChildNodes) { ListRecord currentList = new ListRecord() { Title = listnode.Attributes[3].Value, LastModified = DateTime.ParseExact(listnode.Attributes[10].Value, "yyyyMMdd HH:mm:ss", CultureInfo.InvariantCulture).Year, ItemCount = int.Parse(listnode.Attributes["ItemCount"].Value) }; //web.Lists.Add(currentList); listRecordList.Add(currentList); } List <string> adminList = new List <string>(); adminList.AddRange(GetUsersInRole(web, "Administrator")); adminList.AddRange(GetUsersInRole(web, "Admin")); adminList.AddRange(GetUsersInRole(web, "Beheerder")); adminList = adminList.Distinct().ToList(); web.Administrators = string.Join(",", adminList); if (web.Administrators == string.Empty) { web.Administrators = "-"; } Recursive(web); web.ItemCount = web.Children.Sum(f => f.ItemCount) + listRecordList.Sum(f => f.ItemCount); int listMax = 0; int siteMax = 0; if (listRecordList.Count > 1) { listMax = listRecordList.Max(f => f.LastModified); } if (web.Children.Count > 1) { siteMax = web.Children.Max(f => f.LastModified); } web.LastModified = Math.Max(listMax, siteMax); web.Parent = records.Title; records.Children.Add(web); } }