in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

Ton Stegeman [MVP] weblog

I have moved my blog to http://www.tonstegeman.com/blog. If you have a blogpost at sharepointblogs that does not display all the content on the right hand side, please go to the new blog. It has all the posts that are on this blog as well. I you have any feedback, please send me a message through the contact form.

January 2007 - Posts

  • Using a hyperlink in the group description of a SharePoint group

    In one of the comments on this blogpost on SharePoint sitegroups, I was asked if it is possible to set a hyperlink in the group description, just like SharePoint does out of the box. If you create a new site called “Team”, that site has a sitegroup called “Team Members”. The desciption for that site is: “Use this group to give people contribute permissions to the SharePoint site: Team”. The last part is a link to the site, as you can see in the screenshot below.

    Sitegroupdescription1

    The question how to programmatically set this link in the description. The problem with this is that the Description property is a normal string property, that does not have the HTML value that is displayed above. The trick here is not to use the SPGroup object, but set the property directly on the listitem in a list called “User Information List. This is the list you are looking at when you are viewing People and Groups. Just read the comment in the screenshot above: “There are no items to show in this view of the "User Information List" list.”.

    All site groups (and users) are stored in this list, that is available in the rootweb of your site collection. I have extended the code of the previous example, so that it now also sets the description of the SPGroup to have a nice description with a hyperlink to the site it is used for.

     

        // Initialize
        string customerName = "Contoso";
        string accountManager = @"office2007\jsmith";
     
        // Get the site and the account manager for the new customer site
        SPSite site = new SPSite(string.Format("http://office2007:13145/customers/{0}", customerName));
        SPWeb web = site.OpenWeb();
        SPUser owner = web.AllUsers[accountManager];
     
        // Get the site group
        string groupName = string.Empty;
        SPGroup group = null;
        string groupAssociations = string.Empty;
        groupName = string.Format("{0} Customer Team", customerName);
        group = GetSiteGroup(web, groupName);
     
        // Add the group if it does not yet exist
        if (group == null)
        {
            web.SiteGroups.Add(
                groupName, owner, null,
                groupName);
            group = GetSiteGroup(web, groupName);
        }
        // If the group was created, set the Visitor reference in the site property bag
        // and set the description for the site group.
        if (group != null)
        {
            web.Properties["vti_associatevisitorgroup"] = group.ID.ToString();
            groupAssociations = string.Format("{0};", group.ID.ToString());
     
            // Get the userlist from the rootweb
            SPWeb root = site.RootWeb;
            SPList userInformation = root.Lists["User Information List"];
     
            // Construct and submit the query to find the qroup
            SPQuery query = new SPQuery();
            query.Query = string.Format("<Where><Eq><FieldRef Name='ID'/>
                <Value Type='Text'>{0}</Value></Eq></Where>", group.ID.ToString());
            SPListItemCollection items = userInformation.GetItems(query);
     
            // Update the item if it was found. 
            if ((items != null) && (items.Count == 1))
            {
                SPListItem item = items[0];
                item["About me"] = string.Format("Use this group to add people to the customer
                    support team for site: <a href=\"{0}\">{1}</a>", web.ServerRelativeUrl, customerName);
                item.Update();
            }
        }

    In the last bit of this code example, a reference to the RootWeb of the site collection is set. This SPWeb has a SPList object called “User Information List”. We can find the correct item in this list using the ID of the SPGroup object we just created. We create a SPQuery object and run that against the list. This returns 1 SPListItem object. The description for the site group is stored in a field called “About me” (The internal name of this field is “Notes”). After updating the item and running the code, we now have set the description as we wanted:

    Sitegroupdescription2

  • Copy / Migrate a SharePoint site to another farm by using a SQL Server backup

    I came across this TechNet article when I was searching for ways to copy one SharePoint 2007 web application with all site collections to another farm. In our case we used the steps described under “Migrating using SQL Server Tools” to move databases across farms. In our customer environments (we have a mix of beta2, beta2TR and RTM), the normal backup/restore options did not work. Exporting the site using STSADM also failed. But by using this technique it was very easy to do it.

    And it turned out that it is also a pretty nice and clean way to migrate sites gradually to the RTM version. Here are the steps (described very briefly):

    • Create a SQL backup of the content database(s) of the web application you want to copy/migrate
    • On the destination server, restore the backup in a new database(s)
    • Create a new web application on the destination server (use the default database name proposed by sharepoint)
    • Detach the database
      • Go to Application Management – Content databases
      • Select the correct web application
      • Set the database status to offline
        Backuprestore1
      • Click Add a content database
      • Enter the correct details about your restored database and click OK
      • That’s all

    When I was copying a content database from a Beta2–TR server farm to a server farm running the release version, I got this message when I attached the restored database:
    Attaching this database requires upgrade, which could time out the browser session.  You must use the STSADM command 'addcontentdb' to attach this database.

    Instead of using the user interface I now added the new content database by using STSADM (replace my sample parameters between [ and ]):

    stsadm -o addcontentdb -url [http://office2007:85] -databasename [WSS_Content_85] -databaseserver [OFFICE2007\OfficeServers]

    After running the command I got the message “Operation completed successfully” and my site was up and running in RTM. Please note that you can only use supported upgrades in this scenario; you can go from beta-2 to beta-2 technical refresh and from beta-2 TR to RTM.

  • SharePoint 2007 and cross site groups???

    When I was preparing for beta exam 70–541 I studied all items in the preparation guide. The last item confused me a bit. You should know how to “Add a cross-site group to a site group on different site”. I am confused, because I thought cross site groups no longer existed (or all SharePoint groups are considered to be cross site). The beta exam however, had a few questions about this subject. This made me a bit curious how this works in SharePoint 2007, so I started to look into it. But now I am even more confused…..

    If you look at the object model, a SPWeb object has 2 properties:

    • Groups – this returns all cross site groups for the site (according to the SDK)
    • SiteGroups – this returns all cross site groups for the site collection.

    I created a testprogram that saves the Xml of these groups to a file to compare the differences between the 2.

    • Both properties return the same groups in the document center in a new portal
    • When I create a new group (using the UI) in the document center, it shows up in SiteGroups.
    • When I use “Set Up Groups” in the document center People and Groups to create a new group, it also shows up in SiteGroups.
    • When I setup the document center to have unique permissions and create a new group, it shows up both in Groups and in SiteGroups.

    I is not very clear to me what exactly the difference is between cross site groups for a site and cross site groups for a site collection. In the SharePoint UI there appears to be no difference. Anyone who knows how this works?

    And if you are also preparing for the exam, this blog by Ishai Sagi contains more usefull information.

  • Creating a custom search page for searching a specific search scope in SharePoint 2007

    The search options in MOSS 2007 now have scopes. By using a search scope users of your search pages can easily just search in specific parts of the content. To create a scope, you define rules. These rules have a ‘source rule type’, which can have 3 values:

    • url (‘scope’ the search results based on url)
    • propery query (‘scope’ the search results based on the value of a property (a property restriction)
    • content source (‘scope’ the search results based on the content source they are part of)

    In our intranet we have added a field called ‘InformationType’ to all content that we upload. All our sites that are ‘Knowledge’ related, automatically classify the content in it as Knowledge. By using a scope we can make it much easier for our users to just search in knowledge related content. After that we created a custom search page, specific for knowledge that just searches in ‘Knowledge’.

    Here’s a quick how-to (especially the last step took some time for me to find out….) The trick is that the Search Core Results webpart has a property called “Scope”, which is hidden in the Miscellaneous section, which is not where I expected it…. Here you can manually enter the name of the scope you want to use.

    Here’s a brief How-To:

    1. Create a sitecolumn called InformationType and add at least 2 different values
    2. Attach the sitecolumn to some libraries or lists
    3. Upload/Add some content and select at least 2 different values
    4. Do an incremental crawl of your search index
    5. Create a managed property:
    • Go to the “Metadata property mappings” page (see search options in the SSP)
    • Click “New Managed Property”
    • Enter “InformationType” as the name
    • Click “Add Mapping” and search for your InformationType property (this is why you need to do the crawl in step 4, otherwise it won’t show up).
    • Check “Allow this property to be searched in scopes”
      Search1
  • Run a full crawl on your index
  • Go to “View Scope” in the search settings on your SSP and create a new scope
  • In the Scope overview click “Add Rule” in the “Updates Status” column
  • Set the Scope Rule Type to “Property Query” and add the appropriate property restriction (InformationType equals “Knowledge”)
    Search2
  • Go back to the search settings and click “Start updates now”.  The scopes have to be compiled before they work.
  • Add the InformationType to your scope dropdown (this is an easy one to forget):
    • Go to the top level site settings
    • Click “Search scopes” in the site collection administration setting
    • Click on the link “Search Dropdown” (name of a display group)
    • Check the checkbox for your new “Knowledge” scope
      Search3
    • Get a coffee (it actually takes some time before the scope appears in the dropdown….)
    • Test if the scope works
  • Add a new page (use a page layout that can have webparts) to your site
  • Or alternatively add a new search tab to your search center
  • Add the “Search Box” and the “Search Core Results” webparts to your page
  • In the Miscellaneous section of the Search Box, set the value for “Target search results page url” to your new page (which in my demo case is the homepage of and ordinary WSS teamsite).
    Search4
  • Set the “Scopes dropdown” mode to “Do not show scopes dropdown”
  • And the last one (which took me some time to figure out….): Set the Scope value in the Miscellaneous section to “Knowledge”.
    Search6
  • Test your page:
    Search7

    Users now never have to think about in what content they are searching, they just search “Knowledge” Their search results are just documents from the knowledge collection, instead of all being mixed with all other content that is out there.

     


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts