U2U Blog

for developers and other creative minds

More Visual How-To’s

It seems that my buddy in crime Ted Pattison also has spent some evenings talking to his laptop the last couple of weeks. There are a couple of brand new visual how-to's available on the MSDN site:

Activating Auditing Programmatically for a Single Document Library in Windows SharePoint Services 3.0
Microsoft Windows SharePoint Services 3.0 includes a powerful new infrastructure for auditing user access to pages, and document and list items. You can enable auditing for an entire site collection, but it can be more efficient to enable auditing with more granularities. For example, you might want to enable auditing for one specific list or document library. You can go even further and just enable auditing for one specific list item or one specific document.

Activating Auditing Programmatically for a Site Collection in Windows SharePoint Services 3.0
Microsoft Windows SharePoint Services 3.0 includes a powerful new infrastructure for auditing user access to list items, and documents and pages. In Windows SharePoint Services, auditing is configured on a site collection-by-site collection basis. It just takes a few lines of code to fully enable the auditing for an entire site collection. When you do this, Windows SharePoint Services writes an audit entry to its audit log each time a user views or modifies a list item, document, or site page.

Creating a Feature for an Entry Control Block Item in Windows SharePoint Services 3.0
You can add a custom menu item for an entry control block to a list item or a document in Microsoft Windows SharePoint Services 3.0 by creating a Feature with a CustomAction element. In this way, you can add custom commands to the default SharePoint user interface. These menu commands allow users to perform custom operations on items and documents. For example, you can create a custom menu item for an entry control block for a list item or document that redirects the user to a custom application page. Use this as a starting point to create business solutions that provide an intuitive user interface to automate domain-specific tasks on list items and documents.

Creating a Feature for the Site Actions Menu in Windows SharePoint Services 3.0
You can add a custom menu item to the default Site Actions menu in Microsoft Windows SharePoint Services by creating a Feature with a CustomAction element. In this way, you can add custom commands to the default SharePoint user interface. These commands are available to users as they move between pages on a SharePoint site. When you create a Site Actions menu item, you can configure it to redirect the user to any URL. For example, you can redirect the user to another Web site. You can also redirect users to a custom application page that allows them either to see a custom display of data, or to perform custom operations on the content within the current site.

Creating an Application Page in Windows SharePoint Services 3.0
You can create custom application pages to add user interface components to a custom solution based on Microsoft Windows SharePoint Services 3.0. Unlike site pages (for example, default.aspx), a custom application page is deployed once per Web server and cannot be customized on a site-by-site basis. Application pages are based in the virtual _layouts directory. In addition, they are compiled into a single assembly DLL. They are also used across all sites within a server farm. For these reasons, they perform better than site pages. With application pages, you can also add inline code. With site pages, you cannot add inline code.

Reading ListId and ItemId from an Application Page in Windows SharePoint Services 3.0
In Microsoft Windows SharePoint Services 3.0, you can create a menu item for an entry control block that redirects users to a custom application page. For example, the MSDN article Item-Level Auditing with SharePoint Server 2007 demonstrates how to provide each document within a document library with its own menu item in the entry control block. This menu item redirects the user to a custom application page that displays the audit history for that particular document. When a user clicks a menu item in the entry control block, it runs an application page. The code behind the application page typically must program against the list item or document that supplied the menu item. To do this, the application page must be able to identify the list item or document. Windows SharePoint Services does this by passing the information that identifies the list item or document to the application page in a query string. The page uses this information within the page-initialization code to create an SPListItem object and its containing SPList object.

Good work Teddy boy! Looking forward to next month when we're back on stage together.

This is a good day to start a blog!

Hi Folks!

When my second version of the U2U CAML Query Builder was released a lot of people asked me to start blogging. But at that moment I was pregnant of my second child with the first one not yet 2 years old.

Now it is a better time to start blogging: the children sleep a little longer in the morning - not that much longer, but so what, I wake up a little earlier ;) -  giving me some free time to study my favorite subject: SharePoint 2007.

And that 's what this blog will be about: SharePoint 2007, more specific on CAML, the SharePoint web services, and perhaps peppered with some Business Data Catalog or salted with a breeze of Content Management.

Let me finish this intro with a part of a song of one of my favorite bands:

Hey - let me welcome you ladies and gentlemen
I would like to say hello
Are you ready for some entertainment?
Are you ready for a show?
Gonna rock you gonna roll you
Get you dancing in the aisles
Jazz you razzmatazz you
With a little bit of style
Let me entertain you!

Hope to see you soon on this blog!

‘Go back to site’ url when you delete a site

One of the things that bothers me, and I know that I'm not the only one, is that when you delete a site you don't have a link back to your parent site or to the top level site.

In this post I will explain the steps that you need to do to make a link on that page which directs you to the top level page.

First we need to open up the 'webdeleted.aspx' page which you can find if you go to the LAYOUTS folder in the 12 hive:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS

Once you located the file you can open it using Visual Studio, SharePoint Designer or in the best program Microsoft has ever made, notepad J.

Once the file is open you need to look for "PlaceHolderTitleBreadcrumb" contentplaceholder and you need to paste following code in it:

<asp:Content ContentPlaceHolderId="PlaceHolderTitleBreadcrumb" runat="server">


<a href="<%SPHttpUtility.HtmlEncode(SPControl.GetContextSite(Context).Url, Response.Output);%>">Go back to site</a>




This code will create a link 'Go back to site' which will redirect you to the top level site.


So, I'm glad I can use this link, hope you enjoy it as much as I do.

Data Views and the battle of Database Connections

Yesterday I was writing a demo on the use of Data View web parts from within the SharePoint Designer for our Development courses. I tried to explain how to display a Data View connecting to a SQL Server 2005 database. Piece of cake I thought, but that was far from true.

Firs t I tried to configure my connection into the Data Connection Library task pane: I filled out server name and selected the SQL Server .NET Provider. As I don’t have Single Sign-On configured on my MOSS installation, I opted for filling out username and password. In the next step I got a list of databases and tables to select from so I chose to work with the AdventureWorks database and its ProductCategory table. Next I defined a Filter and Sort order and saved my connection. But when I clicked Show Data to have my Data View filled with data, I got the following error:

Show Data error

This is very weird: I was able to get metadata from the database because I was able to select a table, fields, define a filter and a sort order but I’m not able to view the data. I suspected that there was a problem in the communication between SharePoint Designer and SQL Server 2005.

So I opened SQL Server Profiler to trace the calls done by SharePoint Designer to the AdventureWorks database. When executing the Show Data action again, I found out in the SQL Server Profiler that SharePoint Designer tries to execute following SQL statement:

SELECT [ProductCategoryID], [Name] FROM [ProductCategory]

Execution of this statement in SQL Server 2005 Management Studio taught me that it fails because the AdventureWorks database works with schemas. Schemas in SQL Server 2005 are what namespaces are in .NET: it is a logical structure, a way of grouping tables. The AdventureWorks database has several schemas defined and one of the schemas is Production, under which the ProductionCategory resorts. Following statement works fine:

SELECT p.[ProductCategoryID], p.[Name] FROM [Production].[ProductCategory] p

So, the conclusion is: SharePoint Designer ignores database schemas.

There are 2 solutions to this problem:

  • In the connection configuration wizard select a database but don’t select a table to work with. Instead choose the option to specify a custom SQL statement.custom SQL statement
  • Even better is to work with stored procedures. Follow the same steps as for a custom SQL statement but instead of choosing the option SQL Statement, choose Stored Procedure and select your stored procedure from the list.

Anyway, if you need a query that joins 2 or more tables, you have no other option than to use a custom SQL query or a stored procedure.

A small side node: SharePoint Designer seems to cache certain things because when executing Show Data multiple times, there was nothing to see in the SQL Server Profiler, meaning that no request were sent to the database.

I spent a lot of time looking at this problem and trying to understand why SharePoint Designer didn’t want to retrieve the data from the AdventureWorks database. I hope this post saves you from loosing time.

Copying items from another List

Is there a way to import or copy items from a particular list en past them into another list? I haven't found functionality in SharePoint to do so, but I have a little work around for it.

Let me start by giving you the scenario. Say we have a colleagues list, based on the contacts template, and we fill it up with people I LOVE ( J ) to work with, which are them all so I hope I didn't forgot one.

And we have an empty custom list which we call friends, because my colleagues are also my friends, with 2 columns (Firstname of friend and lastname of friend).

How can we copy or insert the names of the colleagues list into the friends list. Well we can copy them from the datasheet view:

Next thing to do is, paste them in the Datasheet view of the friends list:

When you paste them you could get a warning if one of the other fields is a required field. After pasting them go back to the normal or standard view:


And there you go:

Hope you like this one as I do.

Private fields or Secure fields

During SharePoint sessions I often get the question if you could have permissions on the properties of an item in a List or Document Library. This means that some of the properties of an item can be edited or filled in by someone with the right user permissions.

This is not available out-of-the-box and to make something like this you have to create a Custom Field Type. Because I'm a very polite and nice person, I've created such a private field for you and off course I will make it available on my blog, but let me first show you how it works.

Before you can use the private field you need to deploy it to SharePoint. First you will need to download the PrivateFieldPackage by clicking here. Once you've downloaded the package you need to deploy it. I've deployed with following command line statements:

stsadm -o addsolution -filename "C:\PrivateFieldPackage.wsp"

stsadm -o deploysolution -immediate -allowgacdeployment -name PrivateFieldPackage.wsp -allcontenturls

stsadm -o execadmsvcjobs


Once it is deployed you can use it in Lists or Document Libraries.

  1. Create a List or a Document Library
  2. Create a column and pick "Private Text field" as the type of the column
  3. Next we are going to give a user or group the rights on the field. 
  4. Once the field is created we can add items in the list or library, first I'm going to create an item logged in as myself.
  5. Now I'm going to edit the item logged in as Jan, and you will see that the field is disabled and Jan is not able to fill the item in.

There you go, off course this field is not finished yet, if you have suggestions for the next version of the private fields or you find a little bug, please let me know.

As last I want to thank Jan and Karine for helping me with this field.

Using quickparts in document templates

One of the cool things of working with MS Word 2007 and SharePoint 2007 is the ability of working with Quickparts. You can use Quickparts to give your users the ability to fill in document propertieson the document itself. If you look at the picture below you see that we can fill in the document properties from the document information panel and that they are visualized on the page itself. You can go the other way around as well, by filling them in the Quickpart.

You can do the same with metadata. Metadata is some extra information of your document. You can add metadata to a document library by adding columns to that library. Once you've created the columns you can use these metadata as Quickparts on your document. But the question rises, what if I'm creating a document template? First of all, the document template is the document that you get when you click the new button.

The reason why I got this question is because mostly you create such a template on the client side where you have no a connection to your document library. The solution is fairly simple, just use the document library to create your template. Meaning, don't start on the client side but open the word document by clicking on the new button of your document library.

Let's create a document library, which is based on the word template and add some metadata. I've create a 'My Documents' library and I've added one column which is the 'Description' column. I've pick multiple lines of text as the type for the column.


















To have the connection between your word document and the metadata from the library click the New button, this will open up a new document. Once your document is open you can add a Quickpart which you can find on the Insert tab. You will see that the Description field is now available.

All set and done, if you want to have a nice header and footer, go aheadJ. Save the document on your desktop and not in the document library because we are going to use this one as a template.

Once the document is saved, you need to copy this into the forms folder of the document library. The easiest way to go there is via the 'Open with Windows Explorer' in the Actions menu of your document library.

This forms folder contains all the files to display and work with the document library. You will also find a template file that is used by the document library to open a new document, in our case that is the template.dotx file. If you want to use your own template you can just drag your document into the forms folder.

Once you've dragged your file into that folder you need to specify that you want to use this template. You can do this in the Advanced Settings of your document library, which you can find in the document library settings.

Once on the Advanced Settings page, go to the Document Template section and change the default template to yours.

That's it, just go back to your document library and press the New button.


Customizing Best Bets

One of the things that people are not aware of is that you can customize the search results coming from the SharePoint search engine. The results, which is XML, given by the engine are styled using XSLT. If you create your own XSLT you can customize/restyle your results page.

There is a 'Visual How To' by Patrick Tisseghem explaining the steps you need to do to customize the search page.

You can do the same trick with the Best Bets meaning, you can customize them by applying your own XSLT. Before we are going to customize the Best Bets, let me explain what they do an how you can use them.

Best Bets are used to promote some results depending on your search keywords. If you look at the screenshot below you see that when I type SharePoint in the search box, U2U and Microsoft are pushed forward as results where you definitely can find something about SharePoint. So if you think about it, Best Bets is a way for an administrator to earn some extra money, the one who pays the most gets on top of the list J.

To create these Best Bets, you need to go to the settings page of your top level site and you need to click on the 'Search keywords' linkbutton where you can create the Best Bets by clicking on the create button.

After filling in a keyword you can add Best Bets by clicking on the Add Best Bet button, type in a url, title and description for your best bet.

Now that the Best Bets are created we can test them by typing SharePoint in the search textbox. You will see the results at the right side of the page.

Because they are displayed in a webpart you can drag the webpart into another webpartzone to ,for example, have your best bets before the search results.

Okay, now let's customize our Best Bets. These are basically the same steps as in the 'Visual How To', so you can follow the steps there as well, the only difference is that in the video they customize the search results.

Because the Best Bets webpart is using XSLT to show the results getting from the search engine (which is XML ) we can apply our own XSLT. So if you go to the properties of the webpart you can click on the XSL Editor to replace the existing XSLT with your personal XSLT.

As said, the best bests is nothing more than XML which is styled using XSLT. Because it is not easy to create XSLT, We are going to let SharePoint Designer create the XSLT for us. The only thing that we need to do is saving the XML returned from the search engine so we can use it in the Designer.

To see the XML returned from the engine we need to use following XSLT. Copy it in the XSLT dialog box.

<xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
   <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />

     <xsl:template match="/">
        <xmp><xsl:copy-of select="*"/></xmp>



After saving your new XSLT you can copy the XML and paste it temporarily in an XML file, so we can import this file and use it as a Data Source in SharePoint Designer.

Speaking about the devil, lets open up SharePoint designer to do some customization magic. The first thing that we need to do is using our XML as a Data Source. You can manage your data sources by choosing Manage Data Sources which you can find in the Data View on the menu bar.

Once you've done this, you get an overview of all the available data sources in the toolbox. One of the data source categories is 'XML Files'. In that category you can click on Add an Xml File to add your XML file as a data source.

You can browse to your file and add it to your Data Sources . Once the file is added,you can see the available data by right-clicking on it and pick Show Data from the dropdownlist.

Once the data is shown you can specify what data you want to show for your best bets. Select title, url, description and drag this to your design surface.

Once you've dragged your data on the design surface, you see a menu where you can do some additional settings like adding more columns, allow paging and sorting …. In our case it is more useful to apply another layout so click on change layout and pick one that fit your needs.

Next thing that we need to do is make sure that we can click on the url.

Okay, that's it for now (you can off course customize as much or as advanced if you want), let's go to code view and copy the generated XSLT. Make sure that you copy everything between and including the <xsl:stylesheet> tags.

Copy the XSLT in the XSL Editor in the properties of the Best Bets webpart and save it.

Publish your page and try it out.

RSS Manager

I don't know if this feature already exists but I took the time to create an RSS manager.

When you want to enable RSS on a list or a Document Library you need to go to the list itself. This is not a hard job to do when you don't have many lists or libraries. With this feature you can manage this by just opening a page from the site settings.

You can download the RssManager package by clicking here.

Walkthrough time J.

  1. Install the feature using following command line statements

    stsadm -o addsolution -filename "C:\RssManager.wsp"

    stsadm -o deploysolution -immediate -allowgacdeployment -name RssManager.wsp

    stsadm -o activatefeature -filename rssmanager\feature.xml –url "url of your site"

  2. Create a new Site based on the Team Site Template
  3. Go to the settings page by clicking on "Site Actions" and "Site Settings"
  4. On the page click "RSS Manager"
  5. Once you are on the page you can mark a checkbox to enable RSS on a list or uncheck to disable RSS on the list or library

Yet another feature that will make your SharePoint life better.