Example #1
0
        /// <summary>
        /// Loads the site collection of a Sharepoint server
        /// </summary>
        /// <param name="srcWebs">webs web service</param>
        /// <param name="srcLists">lists web service</param>
        /// <param name="loadListData">load data items or not</param>
        /// <returns>A Sharepoint site collection tree</returns>
        private SSiteCollection LoadSharepointTree(WebsWS.Webs srcWebs, ListsWS.Lists srcLists, bool loadListData)
        {
            SSiteCollection siteCollection = new SSiteCollection();

            // get all webs names (first is the site collection)
            XmlNode allSrcWebs = srcWebs.GetAllSubWebCollection();

            // result<List>: <Web Title="F*****g site collection" Url="http://ss13-css-009:31920" xmlns="http://schemas.microsoft.com/sharepoint/soap/" />
            Dictionary <string, string> webs = new Dictionary <string, string>();

            foreach (XmlNode web in allSrcWebs)
            {
                webs.Add(web.Attributes["Url"].InnerText, web.Attributes["Title"].InnerText);
            }

            bool   firstRun          = true;
            string srcListsUrlBuffer = srcLists.Url;
            var    allSrcWebsXml     = new List <XmlNode>();

            foreach (KeyValuePair <string, string> web in webs)
            {
                // load details on each web
                XmlNode w = srcWebs.GetWeb(web.Key);
                allSrcWebsXml.Add(w);
                SSite site = new SSite();
                site.ParentObject = siteCollection;
                site.XmlData      = w;

                string url = w.Attributes["Url"].InnerText + WebService.UrlLists;

                // only do this, if destination site is being loaded
                if (!loadListData)
                {
                    this.destinationSiteUrls.Add(w.Attributes["Url"].InnerText);
                }

                // get all lists
                srcLists.Url = url;
                XmlNode lc = srcLists.GetListCollection();

                // lists to migrate: Hidden="False"
                foreach (XmlNode list in lc.ChildNodes)
                {
                    // if BaseType==1 --> its a document library
                    if (list.Attributes["Hidden"].InnerText.ToUpper().Equals("FALSE") && !list.Attributes["BaseType"].InnerText.Equals("1"))
                    {
                        // load list details with all fields
                        XmlNode listDetails = srcLists.GetList(list.Attributes["Title"].InnerText);
                        Console.WriteLine(list.Attributes["Title"].InnerText + ", BaseType=" + listDetails.Attributes["BaseType"].InnerText);
                        SList shareList = new SList();
                        shareList.ParentObject = site;
                        shareList.XmlList      = listDetails;

                        // load list data
                        if (loadListData)
                        {
                            // attention: GetListItems only returns the elements of the default view, if you do not specify the viewfields you want
                            XmlDocument xmlDoc     = new System.Xml.XmlDocument();
                            XmlElement  viewFields = xmlDoc.CreateElement("ViewFields");

                            XmlElement field;
                            foreach (XmlElement f in shareList.XmlList["Fields"])
                            {
                                field = xmlDoc.CreateElement("FieldRef");
                                field.SetAttribute("Name", f.Attributes["Name"].InnerText);
                                viewFields.AppendChild(field);
                            }

                            XmlNode listItems = srcLists.GetListItems(list.Attributes["Title"].InnerText, null, null, viewFields, null, null, null);
                            shareList.XmlListData = listItems;
                        }

                        site.AddList(shareList, false);
                        Console.WriteLine("\t\t" + list.Attributes["Title"].InnerText);
                    }
                }

                if (firstRun)
                {
                    site.IsSiteCollectionSite = true;
                    firstRun = false;
                }
                else
                {
                    site.IsSiteCollectionSite = false;
                }

                siteCollection.AddSite(site, false);
            }

            srcLists.Url           = srcListsUrlBuffer;
            siteCollection.XmlData = allSrcWebsXml;

            return(siteCollection);
        }