Please upgrade your web browser now. Internet Explorer 6 is no longer supported.
Zac Smith
SharePoint, WSS and MOSS development.

Configuring search on a public facing Web Content Management (WCM) site is quite a different task compared with your typical SharePoint intranet. Searching over internal content largely works out of the box; setting up a few content sources and basic scopes is usually enough to satisfy most users.

With a public website we want a simpler more ‘bing/google’ like search experience. The method of search is a basic search keyword phrase input and the power of the search resides in the indexing of content. We do not want to rely on a user’s ability to construct complicated search terms. Everybody can use it, and use it effectively.

What follows from here is a basic guide for setting up SharePoint search on an anonymously accessed SharePoint publishing site. This assumes a bit of experience configuring search, but if you don't take a look at this TechNet webcast on installing and configuring search in SharePoint Server 2007.

Creating Scopes

Creating scopes is the most important step in configuring public search. There are usually a number of resource files such as CSS, JavaScript, XSL and images as well as objects like user profiles that you wouldn’t want showing up in your search results. However we do want to be able to search over all of our document libraries, inlcuding aspx pages. So our first step is to create a scope that will return all pages and documents which we can create like this:

Public Search Scope Example

A search using this scope will return anything that is in the content source “Local Office SharePoint Server sites” AND (the content is a publishing page OR the content is a document). Note the brackets used in this statement.

As you can see the rule behaviour is being used to create logical conditions. The logic of the rules can be applied as follows:

  • Include = OR
  • Require = AND
  • Exclude = AND NOT

The ‘contentclass’ property specifies what type the indexed item is and will be automatically available for any content item in SharePoint. The two types that we are usually concerned with in a public site are:

  • STS_ListItem_850 (Publishing Pages)
  • STS_ListItem_DocumentLibrary (Documents)

Check out this post from Dan Attis for a complete list of contentclass values.

Tip

I would recommend against allowing list items in your search scopes. The basic reason for this is that to view a list item you need to browse to the display form (/Forms/DispForm.aspx). Problem is this should be locked down by the Form Lock down feature. Unfortunately it is common for lists to be used to store content for your public web site; for example when using WSS collaboration features such as blogs, wikis and discussion lists. At the end of the day the collaboration and publishing features in SharePoint don’t play very nicely together. When making design decisions for a SharePoint based solution and the question comes up - “Should we put this content in a simple list or create aspx pages?”, you should consider whether you want the content to be searchable or not.

Scope Examples

What if we wanted to create a scope that returned everything under a specific web? In this example I have added folder rule that will include all results in or beneath the 'about-us' site:

Public Scope for a web

 

What if we had a shared server environment that hosted multiple websites? In this example I have added a domain rule so that any results for my site 'http://trinkit' will be returned:

Public Scope for a Site

If you don’t know how to create scopes than have look at this help page from microsoft office online.

Tip

When indexing document libraries make sure that the documents are of a file type known to SharePoint, otherwise SharePoint will crawl the document as a list item and use the form display page rather than the actual document itself. Check out the filter pack from Microsoft if you want to add additional file types.

Creating a Simple, Deployable Layout

Armed with our public search scopes we already have enough information to return the right results. The next step is to create a simple search page to display search results.

When you create a search centre using the out-of-the-box search site template, you get a whole bunch of features that just aren’t that well suited to a public facing scenario (RSS Feeds, Alerts, Advanced Search). My recommendation is to take a light weight minimal approach - why use a whole search centre when a single results page will do it? Creating a single page layout that is part of an easily deployable SharePoint solution is often the cleanest way to go.

Web Parts

Web Part zones often cause issues when it comes to repeatable deployment and they add additional HTML bloat. If you are wanting the simplest HTML output possible then web part zones should be avoided.When it comes down to it we only really need a page layout with a few basic web parts – SearchBoxEx, CoreResultsWebPart and the SearchPagingWebPart.

Here is an example of using the CoreResultsWebPart in a search page layout without web part zone.

<Search:CoreResultsWebPart runat="server" 
    ID="SearchResults" 
    ShowActionLinks="True" 
    Scope="All Pages and Documents"  
    HighestResultPage="1000" 
    DuplicatesRemoved="True" 
    DisplayDiscoveredDefinition="True" 
    ShowSearchResults="True" 
    FrameType="None" 
    NoiseIgnored="True" 
    StemmingEnabled="True" 
    View="Relevance" 
    QueryNumber="Query1" 
    SentencesInSummary="3" 
    ResultsPerPage="10" 
    DateFormat="DateOnly" 
    DisplayAlertMeLink="False" 
    DisplayRSSLink="False" 
    RelevanceView="True" 
    WebPart="true">
    <XslLink>/XSL/CoreSearchResults.xsl</XslLink>        
    <SelectColumns>
        <root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <Columns>
                <Column Name="WorkId"/>
                <Column Name="Rank"/>
                <Column Name="Title"/>
                <Column Name="HitHighlightedProperties"/>
                <Column Name="Size"/>
                <Column Name="Path"/>
                <Column Name="Description"/>
                <Column Name="PictureThumbnailURL"/>
                <Column Name="SiteName"/>
                <Column Name="CollapsingStatus"/>
                <Column Name="HitHighlightedSummary"/>                
                <Column Name="ContentClass"/>
                <Column Name="IsDocument"/>
                <Column Name="Write"/>
                <Column Name="Author"/>
                <Column Name="ContentType"/>
            </Columns>
        </root>
    </SelectColumns>        
</Search:CoreResultsWebPart>

The other web parts can be added to the page layout in the same way.

Tip

Make sure search.js is inlcuded in a custom search page layout as it is needed for logging search statistics: 

<asp:Content ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <SharePoint:ScriptLink ID="ScriptLink1" name="search.js" runat="server"/>
</asp:Content>

  

Additional Branding Considerations

The majority of the branding is quite easy due to the core search results web part using an XSL transformation to style the results. Unfortunately the other web parts will require tedious battling with overriding of SharePoint’s CSS properties. Not ideal but you can still get it looking pretty decent if you know what you are doing.

For full control of the HTML structure and styling you would need to create a bespoke solution that used the search SQL Syntax API that comes with MOSS. This is also the only solution if you require some advanced sorting or filtering functionality. This isn't overly difficult, but it's a tough one to explain to the business owner that is forking out for SharePoint.

So what about advanced search? I think we’ll leave that one for another day.

I hope this post gives you a few ideas and some "best practices" on you can go about creating a decent search solution for you public SharePoint website.

Good luck!

Categories: Development, MOSS, Search, SharePoint, WCM
Recently there have been a few key improvements to the STSADM backup command which I have found to make life a lot easier (and safer!).

After installing Service Pack 2 and running the backup command you will notice a few subtle, but important changes:


Previously it was a best practice to set the site being backed up to read only using the setsitelock command. This is something that I am guessing 95% of people never did. And who can blame them as it wasn't made terribly obvious. Fortunately the backup command now automatically sets this and lazy admins can have peace of mind.

The April CU also provided an important update to how backup and restore works, particularly with publishing sites. In SharePoint, the actual page layout aspx files are stored with some hardcoded metadata which includes the url of the site they belong to. Previously when performing a backup & restore to different farms with different URLs this could cause issues. Import/Export does not have this problem as the page layouts are recreated in the target site. The backup command has now been updated to fix this issue and this method of migrating content between farms is now supported. Note that the June CU is now available and supersedes the April CU.

So why would you want to use backup/restore over import/export to migrate content anyway?
If you commonly use the SPSiteDataQuery class, ContentQuery webpart or the DataView webpart you rely on GUID references to lists for query commands. By default, import/export assigns new GUIDS to any lists that are migrated which will upset the queries that rely on them. Using backup/restore was an easy way to avoid this issue.

Of course it was fairly easy to write some import code using the object model and retain the GUID values. And if you still want to use import/export that is the way to go.
Categories: MOSS, WCM, Development, Infrastructure, SharePoint, WSS
I don’t particularly enjoy installing SharePoint, I’ve done it a million times and really it’s quite a boring process. When I do end up having to install it, I generally use a simple 4 account method:

  1. Admin (SPAdmin) - Used for installation and administration of SharePoint
  2. App Pool  (SPAppPool) - all web apps except central admin run with this account as their identity
  3. Services (SPService) - App pool account for central admin and the SSP service account
  4. Search (SPSearch) - Used for all search services
Generally I’m installing SharePoint for my own dev/test purposes, so this suits just fine. I think it is also fine for small scale installations or instances when the admin in charge of account creation isn’t interested in creating 8+ accounts. To be honest I think a lot of the time using the 8+ accounts is a tad overkill, and people are just blindly following ‘best practices’ without applying them to their specific environment. But being more of a dev type than an infrastructure type I don’t feel qualified to formally make that recommendation.

Even for a development server it is really important to have some separation of accounts. It is in your best interest to simulate a production scenario as best you can. Take for example if you were to use the SharePoint admin account as an application pool identity. You may have permissions to do things on your dev server (in code) that will probably have issues in a production scenario.
Categories: Development, MOSS, SharePoint, WSS
Sales, marketing, project managers and even IT managers always seem to latch onto the concept of building a web part to provide custom functionality in SharePoint. I’m always being asked to create a web part for various tasks which just complicates things. In reality 95% of the time a web control will do the job just fine, or better yet a user control.
 
A web part usually dictates that you will be dynamically creating asp.net controls at runtime or writing HTML tags in managed code. Both of these techniques are pretty horrible and provide no separation between logic and presentation. There are many examples of this on CodePlex.
 
A user control has a few key advantages over web parts:
  • Easier development: User controls provide a design time surface and allows easier HTML integration
  • Easier deployment: There are less steps required to make a user control available in a SharePoint site
  • Less unwanted HTML: Web parts and the web part framework include additional HTML bloat that decreases accessibility
That said there are a few good reasons why you would want to build a web part:
  • Reusability: If the component is going to be used in multiple pages with different configurations
  • Admin control: Web part properties provide a convenient way for admins to manage settings
  • Collaboration: Where users or content authors want to be able to add web parts to their own pages
If you decide that you do need a web part, I would still advocate using a user control. You can either use something like SmartPart, or preferably just embed it yourself as it’s a very simple task. By embedding a user control to a web part in a 1-1 relationship, you have the opportunity to use web part properties as well as providing the best user experience.
 
The same theory can be applied to field controls. Another option when creating web parts is to use XSLT to control the display. I believe this is a great approach as it provides good separation between logic and presentation, makes it easier for integrators and promotes accessible HTML.
 
I guess web parts just sound cooler?
 
Resources:
Categories: Development, MOSS, SharePoint, WSS, WCM

Sometimes when updating a custom theme it can be really difficult to get your changes to take effect.

Normally the process to update a theme would be something like:

  1. Copy new theme files to theme directory
  2. Change selected theme to any other theme in site settings
  3. Perform an IISRESET
  4. Re-apply theme in site settings

However, sometimes no matter how hard you try it just won’t update. In fact even if you manually update the cached theme css file in SharePoint Designer (in the _themes dir) it just reverts back to the previous version.

Turns out there is an extra step after copying your theme files in. You need to update the version settings in the theme.INF file. If I was changing this for the SIMPLE theme I would find the file to edit in the following directory:

Theme Location

And the values that need to be updated are highlighted below:

 Theme INF File

I normally just increment the numbers each time as with any versioning.

Follow the rest of the steps and you should have no trouble.

Here are a couple of related resources:

Categories: Development, SharePoint, WSS, MOSS

There are a lot of cool things you can do when working with profile functionality in SharePoint - e.g. people search, my sites, audiences, people based workflow, profile management..

 

But when it comes to developing and testing it can be hard to tell how well things are working unless you have a bunch of test users with meaninful profile data.

 

If you've ever used one of Microsofts virtual machines that come with the litware test domain, you'll be familiar with Don Funk, Brian Cox and the rest of the gang. Those are all active directory accounts with profile data including direct reports which is great for testing org charts.

 

So how can we get those accounts into our own AD domain?

Easy - Use the LDFIDE tool that comes with windows server. Exporting the accounts into a file and importing that file into a different domain does present a number of problems: the domain name is different, many exported fields are read only, passwords cannot be imported. I've gone ahead and solved those problems for you, so if you want to import those users into your own domain just follow these steps:

  • Download the Sample Users text file. Replace the test domain values with your own. I use DC=mossdev,DC=local. I also have all email addresses going to mossdev.com which is a local mail service. I have a catch all email account setup so that all emails to my users feed into the one outlook inbox. I have also specified an OU called Profile Accounts to keep them seperate from all of the default accounts.
  • From the command prompt run
      ldifde -i -k -f c:\sampleadusers.txt
    To import all the users, you will need to keep running the command until all users have been processed. This is because of the dependicenies between managers/direct reports.
  • Download the Update Passwords text file and replace unicodePwd with your own base64 encoded password. The password in that text file is "P@ssw0rd" which I often use for test accounts. If you are encoding your own password its important to use a unicode encoding of a string. The string value would look something like "\P@ssw0rd\". You'll only need the passwords if you actually want to log in with the accounts.
  • From the command prompt run
     ldifde -i -h -f c:\updatepasswords.txt
    to update all the passwords.

Now you should have a domain of 78 users full of profile info that you can play with.

Now I can log in as Don, create a mysite and view his profile properties along with org chart:

 
dons profile
 
 
Categories: MOSS, SharePoint, WSS, Search, Development

Tech-Ed New Zealand 2008

by Zac Smith 29-Aug-08, 0 Comments
Tech-Ed New Zealand is just around the corner, and I'm really looking forward to it. This year I'm involved in co-presenting two sessions:
 
 
OFC301 - Creating Content Centric Publishing Sites with MOSS 2007.

Mark Orange and Zac Smith
Tuesday 2nd September
3:45 - 5:00 pm
NZRoom 3 SkyCity

This session focuses on using the Web Content Management features of Microsoft Office SharePoint Server 2007 to build rich content web sites. Learn how users can create web pages and manage the publishing process using core SharePoint features. Then walk through some code and demos using Microsoft Visual Studio and SharePoint Designer to understand the SharePoint web page model and to learn some good software development processes when developing web sites on Microsoft Office SharePoint Server 2007.
 

OFC303 - Tools and techniques for productive and effective SharePoint development.

Matt Smith and Zac Smith
Wednesday 3rd September
3:45 - 5:00 pm
NZ Room 3, SkyCity

In this deep-dive, demo-oriented session for developers, we look at tools and techniques for maximising productivity and effectiveness when customising SharePoint. Topics will include: productive build cycles, development environment optimisation, best practices, “I didn’t know SharePoint designer could do that!”, innovative use of Powershell and working effectively in teams.  Community tools and extensions that assist developer effectiveness will also be covered in detail in our section: don’t be a tool, be a better developer through tools!
 

If you can't make it along on the day, DPE New Zealand are running ‘Tech.Ed Live’, an online version of Tech.Ed, to complement the offline event. It’s a way to share some of the content and general Tech.Ed goodness with the unfortunate souls who couldn’t get tickets.
Check it out here: www.techedlive.co.nz

Hope to see ya'll there!
 
 
Tech-Ed 2008
Categories: Community, Development, MOSS, SharePoint, WCM, WSS

Just posting a quick script for updating all 'Pages' libraries to have approval turned on. To create the script use a console app and add references to Microsoft.SharePoint.dll and Microsoft.SharePoint.Publishing.dll. Enjoy!

// get site collection url
if (args.Length != 1)

    Console.WriteLine("Please supply a site collection URL"); 
    return;
}

string siteName = args[0];  

// iterate through each sub site
SPSite site = new SPSite(siteName);
foreach (SPWeb web in site.AllWebs)

    // look for a pages lib 
    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
    try 
   
        // turn on approval 
        SPList pages = pubWeb.PagesList; 
        pages.EnableModeration = true
        pages.Update(); 
        Console.WriteLine("Updated site: {0}" , web.Title); 
   
    // ignore errors that occur if not a publshing site 
    catch { continue; }
}
Console.WriteLine("Finished ...");

Categories: