コード例 #1
0
        static void Main(string[] args)
        {
            // Gebruik eerste parameter als url en tweede als titel, optioneel

            WebRecord records = new WebRecord();

            if (args != null)
            {
                if (args.Length < 1)
                {
                    records.Url = defaultUrl;
                }
                if (args.Length < 2)
                {
                    records.Title = defaultTitle;
                }
            }
            else
            {
                records.Url   = defaultUrl;
                records.Title = defaultTitle;
            }

            Recursive(records);

            using (StreamWriter fileStream = new StreamWriter(fileLocation))
            {
                string sharepointJSON = Newtonsoft.Json.JsonConvert.SerializeObject(records);
                fileStream.WriteLine(sharepointJSON.ToString() + Environment.NewLine);
            }
        }
コード例 #2
0
        private static List <string> GetUsersInRole(WebRecord web, string role)
        {
            List <string> adminList = new List <string>();

            try {
                UserGroup permissionsProxy = new UserGroup();
                permissionsProxy.Url         = web.Url + "/_vti_bin/usergroup.asmx";
                permissionsProxy.Credentials = credential;
                //permissionsProxy.CookieContainer = GetAuthCookies();

                XmlNode groups = permissionsProxy.GetGroupCollectionFromRole(role);

                foreach (XmlNode group in groups.ChildNodes[0].ChildNodes)
                {
                    XmlNode users = permissionsProxy.GetUserCollectionFromGroup(group.Attributes["Name"].Value);
                    foreach (XmlNode user in users.ChildNodes[0].ChildNodes)
                    {
                        adminList.Add(user.Attributes["Name"].Value);
                    }
                }
            }
            catch (Exception ex)
            {
                adminList.Add("Kon data niet inladen voor role: " + role);
            }
            return(adminList);
        }
コード例 #3
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);
            }
        }