Mads Nissen

backlog on sharepoint, crm, office, .net development, architecture and more..

  • 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 */); 
            }

  • Change WebPart Properties through the WSS Web Services API

    I am currently working on WSS Site generation, and one important aspect of this is to set custom WebPart properties after a site is generated. In this case we are generating a WSS team site for MS CRM Opportunity objects. The WSS site is generated based on a template that contains a set of custom WebParts to display and work with Opportunity data from MS CRM.

  • Adding links to MySite from any page in Sharepoint

    On selected portal areas and teamsite pages in Sharepoint you'll get that link "Add to My Links". This link will append an entry of the current url to your MySite "My Links" list. However this feature is not availible on logical locations like the WSS Team Site default.aspx.

  • Displaying Exchange public folders in Sharepoint

    The Sharepoint / Exchange relationship is not exactly mature. I find myself struggeling to explain customers why seemingly simple stuff is kinda hard. A feature that have been requested by nearly all of our customers is to view exchange public folder contents in a Sharepoint site. So far we've done it in a couple of different ways.

  • Customize Outlook Web Access display elements

            private string OwaDisplayScript
            {
                get
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("<script language='JavaScript'>function window.onload()");
                    sb.Append("{");
                    sb.Append("var form = document.forms[0];");
                    sb.Append("if( form.document.readyState == 'complete' )");
                    sb.Append("{");
                    sb.Append("var oStyles = form.document.createStyleSheet();");
                    sb.Append("oStyles.addRule( '.tblFolderBar', 'display:none' );");
                    sb.Append("oStyles.addRule( '.trToolbar', 'display:none' );");
                    sb.Append("}");
                    sb.Append("}</script>");
                    return sb.ToString();
                }
            }