Register site in Sharepoint programatically

        /// <summary>
        /// Eventhandler that invokes the RegisterInSiteDirectory method. Will only run on the SPS server 
        /// with SPS admin as current identity.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, System.EventArgs e)
        {
            Hashtable itemData = new Hashtable();
            itemData.Add("CustomCategory", "SomeData");
            this.RegisterInSiteDirectory("SiteDirectory", "Sites", "Generated Site Name", "Some Description", "http://sps2003base:8080/sites/genepool", itemData);
        }
        /// <summary>
        /// Registers a site in a given site directory and enlists site for search in the same manner as 
        /// the Sharepoint Site Directory Area UI
        /// </summary>
        /// <param name="siteDirectoryAreaName">Name of the Site Directory area.</param>
        /// <param name="siteDirectoryName">Name of the Site Directory List.</param>
        /// <param name="title">Site Title to be used in the list and search entry.</param>
        /// <param name="description">Site Description to be used in the list and search entry.</param>
        /// <param name="siteUrl">Site Description to be used in the list and for crawling.</param>
        /// <param name="itemData">Custom site metadata used in the list and included in portal content search.</param>
        public void RegisterInSiteDirectory(string siteDirectoryAreaName, string siteDirectoryName, string title, string description, string siteUrl, Hashtable itemData)
        {
            SPSite portalSite = new SPSite("http://sps2003base:8080");
            SPWeb siteDirectoryArea = portalSite.AllWebs[siteDirectoryAreaName];
            SPList siteDirectoryList = siteDirectoryArea.Lists[siteDirectoryName];
            
            // Create new item in the list
            SPListItem item = siteDirectoryList.Items.Add();
            
            // Set default and required values
            item["SiteTitle"] = title;
            item["SiteURL"] = siteUrl;
            item["Description"] = description;
            
            // Add custom metadata
            foreach(DictionaryEntry entry in itemData)
            {
                item[entry.Key.ToString()] = entry.Value;
            }
            
            item.Update();
            // Register the site for search
            Uri siteUri = new Uri("http://sps2003base:8080"); 
            TopologyManager tm = new TopologyManager(); 
            PortalSite site = tm.PortalSites[siteUri]; 
            PortalContext portalContext = PortalApplication.GetContext(site); 
            AreaManager.SuggestDeepCrawl( portalContext, 
                title, 
                description, 
                siteUrl, 
                "" /* LargeIconUrl */, 
                "" /* SmallIconUrl */, 
                "$$$default$$$" /* Index Catalog */, 
                "$$$default$$$" /* Index Scope */); 
        }

2 Comments

Comments have been disabled for this content.