Exemplo n.º 1
0
        /// <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);
            }
        }
Exemplo n.º 2
0
        /// <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());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get all web information records in a paginated way
        /// </summary>
        /// <param name="page">The page number starts from 1</param>
        /// <param name="pageSize">The number of records in each page</param>
        /// <param name="maxPageIndex">Output the max page number</param>
        /// <param name="criteria">An params array contains the Linq to Entity expressions to be used in the where clause to union all the matching records</param>s
        /// <returns>Returns the enumerable of the current page records</returns>
        public IEnumerable <WebInformation> GetAllWebs(int page, int pageSize, out int maxPageIndex, params Expression <Func <WebInformation, bool> >[] criteria)
        {
            if (page < 0)
            {
                throw new ArgumentOutOfRangeException("page");
            }
            else if (pageSize <= 0)
            {
                throw new ArgumentOutOfRangeException("pageSize");
            }
            int totalCount = Sites.Count();

            maxPageIndex = totalCount / pageSize;
            if (totalCount % pageSize != 0)
            {
                maxPageIndex++;
            }
            Expression <Func <WebInformation, int> > sort = s => s.Id;
            IQueryable <WebInformation> webs = null;

            foreach (var c in criteria)
            {
                var matches = Webs.Where(c);
                webs = webs == null ? matches : webs.Union(matches);
            }
            var result = (webs ?? Webs).OrderBy(sort).Skip((page - 1) * pageSize).Take(pageSize).ToList();

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebConnector"/> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="webUrl">The web URL.</param>
        public WebConnector([NotNull] SpContext context, [NotNull] Uri webUrl)
        {
            Assert.ArgumentNotNull(context, "context");
            Assert.ArgumentNotNull(webUrl, "webUrl");

            this.WebsWebService = new Webs();
            this.WebsWebService.SetServer(webUrl, context);
        }
Exemplo n.º 5
0
        /// <summary>
        /// News the webs web service.
        /// </summary>
        /// <returns></returns>
        public Webs NewWebsWebService()
        {
            Webs ws = new Webs();

            ws.Url         = siteUrl + "Webs.asmx";
            ws.Credentials = Credentials;
            return(ws);
        }
Exemplo n.º 6
0
        private static Uri GetSiteAddress(Uri uri, out ClassifyResult result)
        {
            result = null;
            Uri result2;

            using (Webs webs = new Webs(uri.GetLeftPart(UriPartial.Authority)))
            {
                webs.Credentials = CredentialCache.DefaultCredentials;
                try
                {
                    Uri uri2 = new Uri(webs.WebUrlFromPageUrl(uri.ToString()));
                    if (string.Compare(uri2.ToString().TrimEnd(new char[]
                    {
                        '/',
                        '\\'
                    }), uri.ToString().TrimEnd(new char[]
                    {
                        '/',
                        '\\'
                    }), StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        result = new ClassifyResult(new SharepointSiteId(uri2.OriginalString, UriFlags.Sharepoint), uri, UriFlags.Sharepoint);
                    }
                    else if (uri.Segments.Length == uri2.Segments.Length + 1 && string.Compare(uri.Segments[uri.Segments.Length - 1], "default.aspx", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (LinkClassifier.CheckIfLinkExists(uri, null))
                        {
                            result = new ClassifyResult(new SharepointSiteId(uri2.OriginalString, UriFlags.Sharepoint), uri, UriFlags.Sharepoint);
                        }
                        else
                        {
                            result = new ClassifyResult(null, uri, UriFlags.Other);
                        }
                    }
                    return(uri2);
                }
                catch (SoapException)
                {
                    result = new ClassifyResult(uri, ClassificationError.ObjectNotFound);
                }
                catch (WebException)
                {
                    throw;
                }
                catch (InvalidOperationException)
                {
                    result = new ClassifyResult(null, uri, UriFlags.Other);
                }
                catch (NotSupportedException)
                {
                    result = new ClassifyResult(null, ClassificationError.ConnectionFailed);
                }
                result2 = null;
            }
            return(result2);
        }
Exemplo n.º 7
0
        public Webs GetWebs()
        {
            var webs = new Webs();

            try
            {
                var       siteId    = SPContext.Current.Site.ID;
                string    sqlQuery  = string.Empty;
                DataTable dtAllWebs = null;
                SPSecurity.RunWithElevatedPrivileges(() =>
                {
                    using (var spSite = new SPSite(siteId))
                    {
                        try
                        {
                            QueryExecutor queryExecutor = new QueryExecutor(SPContext.Current.Web);
                            sqlQuery  = string.Format("select WebId, WebUrl from RPTWeb where [SiteId] = '{0}'", siteId);
                            dtAllWebs = queryExecutor.ExecuteReportingDBQuery(sqlQuery, new Dictionary <string, object>());
                        }
                        catch { }

                        if (dtAllWebs != null && dtAllWebs.Rows.Count > 0)
                        {
                            for (int i = 0; i < dtAllWebs.Rows.Count; i++)
                            {
                                string webUrl = Convert.ToString(dtAllWebs.Rows[i]["WebUrl"]);
                                if (webUrl.Trim().EndsWith("/"))
                                {
                                    webUrl = webUrl.Remove(webUrl.Length - 1);
                                }
                                webs.collection.Add(new Webs.Web {
                                    id = (Guid)(dtAllWebs.Rows[i]["WebId"]), url = webUrl
                                });
                            }
                        }
                    }
                });
            }
            catch (Exception exception)
            {
                if (exception is AggregateException)
                {
                    exception = ((AggregateException)exception).Flatten();
                }

                webs.error = new Error
                {
                    message    = exception.Message,
                    stackTrace = exception.StackTrace,
                    kind       = typeof(Exception).ToString()
                };
            }

            return(webs);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Get web record by URL
        /// </summary>
        /// <param name="url">The web URL</param>
        /// <returns>Web information entity</returns>
        public WebInformation GetWeb(string url)
        {
            var tmp = new WebInformation()
            {
                Url = url,
            };
            var existed = Webs.FirstOrDefault(w =>
                                              w.Name == tmp.Name &&
                                              w.UrlDomain == tmp.UrlDomain &&
                                              w.UrlPath == tmp.UrlPath);

            return(existed);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Initialize the Webs Web Service
 /// </summary>
 private void InitialiseWebsWebserviceProperties()
 {
     //_websWS = new Webs.Webs();
     _websWS = new Webs(GetHostName());
     _websWS.PreAuthenticate = true;
     _websWS.Credentials     = _sharepointCredentitals;
     //_websWS.Credentials = new NetworkCredential("thushari.desilva", "Clayton123", "adweb");
     if (!_originalSiteUrl.EndsWith("/"))
     {
         _originalSiteUrl = _originalSiteUrl + "/";
     }
     _websWS.Url = _originalSiteUrl + "_vti_bin/webs.asmx";
 }
Exemplo n.º 10
0
        /// <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);
            }
        }
Exemplo n.º 11
0
 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;
     }));
 }
Exemplo n.º 12
0
        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);
            }
        }
 /// <summary>
 /// Initialize the Webs Web Service
 /// </summary>
 private void InitialiseWebsWebserviceProperties()
 {
     //_websWS = new Webs.Webs();
     _websWS = new Webs(GetHostName());
     _websWS.PreAuthenticate = true;
     _websWS.Credentials = _sharepointCredentitals;
     //_websWS.Credentials = new NetworkCredential("thushari.desilva", "Clayton123", "adweb");
     if (!_originalSiteUrl.EndsWith("/"))
     {
         _originalSiteUrl = _originalSiteUrl + "/";
     }
     _websWS.Url = _originalSiteUrl + "_vti_bin/webs.asmx";
 }