Monday, March 28, 2011

SharePoint 2010 Content Query Web Part and Lookup Field Types

I know the topic of the Content Query Web Part (CQWP) and lookup fields has been covered pretty extensively, but I haven’t found an article anywhere that specifically makes this clear. When including a lookup field in the CommonViewFields property on the CQWP, you have a choice of specifying either “Lookup” or “MultiLookup” as the field type. I haven’t been able to find the latter option documented anywhere.

I’ll use the “Posts” list from the standard Blog site template as an example. It has a multi-value lookup column called “PostCategory” that references the “Categories” list. If you want to include this column in your query and expect to get back a complete dataset, you should set the CommonViewFields property to this:

<property name="CommonViewFields" type="string">PostCategory,MultiLookup</property>

If you don’t specify “MultiLookup” as the field type, any blog posts that have more than one category assigned will be returned in the dataset minus the category that has the lowest internal ID. So if you had some SharePoint-oriented categories like Architecture (ID=1), Administration (ID=2), and Development (ID=3) assigned to a post and you specified “Lookup” as your field type in the CQWP, you’d get back the following value for PostCategory in the returned XML:

PostCategory=”2;#Administration;#3;#Development”

Obviously this is bad. It seems odd that the query behaves this way. I would expect it to only return the first category, not everything else. To fix it, simply make sure you use “MultiLookup” instead. The returned value would then look like this:

PostCategory=”Architecture;#2;#Administration;#3;#Development”

Monday, March 14, 2011

Add global navigation to SharePoint 2010 Search Center

-- 11/29/2011 UPDATE --
Thanks to Falk and Furiant for the comments and troubleshooting. I've added an extra step to account for situations where users have read-only permissions. The corev4.css style sheet does not get loaded by default on minimal.master for these users and therefore does not style the navigation properly.

John Ross from SharePoint 911 has an article that describes why SP2010 search center templates use minimal.master for their master pages.

http://www.sharepoint911.com/blogs/john/archive/2010/05/12/sharepoint-search-center-uses-minimal-master-%E2%80%93-and-why-you-should-care-about-that.aspx

One of the most frequent requests I get from users that have (fairly) vanilla SP2010 deployments is to have the global navigation links included on search pages. The simplest way to do this is to make a copy of minimal.master and copy a div tag from v4.master. Here are the steps:

1. Open SharePoint Designer and connect to the root of the site collection where your search center lives. You’re going to need to access to the master page gallery.

2. Select “Master Pages” from the “Site Objects” pane on the left.

3. Make a copy of “minimal.master” and name it something nice like “search.master”. Open this new master page in split view.

4. Find the div tag that encloses the “PlaceHolderTitleBreadcrumb” content place holder control and paste in this markup (which I just copied out of v4.master) right above it.

<div class="s4-lp s4-toplinks">
    <asp:ContentPlaceHolder id="PlaceHolderTopNavBar" runat="server">
        <asp:ContentPlaceHolder id="PlaceHolderHorizontalNav" runat="server">
            <SharePoint:AspMenu
                ID="TopNavigationMenuV4"
                Runat="server"
                EnableViewState="false"
                DataSourceID="topSiteMap"
                AccessKey="<%$Resources:wss,navigation_accesskey%>"
                UseSimpleRendering="true"
                UseSeparateCss="false"
                Orientation="Horizontal"
                StaticDisplayLevels="2"
                MaximumDynamicDisplayLevels="1"
                SkipLinkText=""
                CssClass="s4-tn"/>
            <SharePoint:DelegateControl runat="server"
                ControlId="TopNavigationDataSource" Id="topNavigationDelegate">
                <Template_Controls>
                    <asp:SiteMapDataSource
                        ShowStartingNode="False"
                        SiteMapProvider="SPNavigationProvider"
                        id="topSiteMap"
                        runat="server"
                        StartingNodeUrl="sid:1002"/>
                </Template_Controls>
            </SharePoint:DelegateControl>
        </asp:ContentPlaceHolder>
    </asp:ContentPlaceHolder>
</div>

5. Find the CSS registration tag for minimalv4.css and paste in this tag right above it.

<SharePoint:CssRegistration Name="corev4.css" runat="server"/>

6. Save, check in, and publish the new master page.

7. Browse to your search center and change the site master page to use the one you just published. Your global navigation should now show up directly below the dark blue band that has the site logo and title.