SharePoint Stuff

A collection of helpful tips and resources on maximising the value from a SharePoint Portal Server and Windows SharePoint Services Implementation.

Friday, February 24, 2006

The pointlessness of the - Add(String, Byte[], Microsoft.SharePoint.SPUser, Microsoft.SharePoint.SPUser, System.DateTime, System.DateTime) Method

The Add(String, Byte[], Microsoft.SharePoint.SPUser, Microsoft.SharePoint.SPUser, System.DateTime, System.DateTime) Method in SharePoint allows you to programmatically upload documents and is the only way the "Created By" field can be set to any user other than the one doing the upload.

However according to the MSDN documentation
"This Add method works on a Site Document Library, however, if you use it with an Area Document library, the call will fail with an "Access Denied" error. However, if you do not include the last 4 parameters in the Add method, the file will be added to the Area Document library, but you will not be able to change the Author and document times. "

Gotta love it - this means that the Add method will only allow you to change the Created By for document libraries in the Home Area of the portal (since that is the only Site document library). What is even the point of such a method.

If you try and run it against any other document library you get the following message
"Exception!: Access is denied.(Microsoft.SharePoint)
at Microsoft.SharePoint.h.a(UnauthorizedAccessException A_0)
at Microsoft.SharePoint.Library.a.a(String A_0, String A_1, Object A_2, PutFileOpt A_3, String A_4, String A_5, Int32 A_6, Int32 A_7, Object A_8, Object A_9)"

The only way around is to upload the document using the Add method with no parameters, then directly updating the Created By and Updated By fields in the database using a query such as

update UserData
set tp_author=xx,
where tp_listid='57DF4BF7-F35D-4C6E-AF61-077F6234DDC9'
and tp_id=zz;

xx: is the tp_id from UserInfo table for the user you want to set the Created by Field to. Remember there are multiple users with the same tp_id, so filter down by username as well as site_id
yy: as above but updates the Modified By field.
tp_listid: GUID of the list where the documents exist - find the guid from the docs table
tp_id: is the doclibrowid from the docs table. Remember it is just a sequential number and you need to find the id for the listid you are interested in.

And thats it.

Thursday, February 23, 2006

How to re-create Site Summary Page

If you ever delete the Site Summary page and want to recreate it, do the following

1. In the Home Area click "Change Settings". Go to the "Page" tab and select "SubAreas can use any template"
2. Click OK
3. Then click "Manage Portal Site" and click "Create Area".
4. Enter the details for your new Area - and select "Site Directory Area Template" from the Template Selection box.

And you're done.

Edit Search Results/Sites Summary Pages

There are certain pages in SharePoint where clicking "Edit Page" on the nav doesn't really give you any options. It doesn't allow you to remove or change properties of any webparts nor does it provide the Add Web Part menu. The main pages affected by this "unique feature" are the Search Results page and the Sites Summary Page. On any of these pages add


to the end of the web address and you should see the same edit page capabilities as in all other sections.

SharePoint Portal Server Meta Data Search Myth
The above link is an excellent description on how to set up SharePoint to allow you to search on custom meta data that have been added in your document libraries.

There are however a couple of details to note about this advanced search functionality, that isn't commonly known.

1. While the custom fields exist in the documents and document libraries, if you change the "Search by type" drop down to either "Document Libraries" or "Documents" these additional items disappear and only the default search fields are available. To use the custom fields please ensure that the "Search by Type" is set to "[Any Type]".

2. Secondly, and more importantly, the web page fails to mention how Word and SharePoint deal with custom meta data. In the web page all examples use meta data that is entered manually, as in they are free text boxes, not selected from a SharePoint List. When using values from a SharePoint list the id of the value is stored rather than the actual value. To better illustrate what I mean please
• In any area create a custom list called “CountryList” with 1 field called “Value”. Populate it with your choice of country names.
• Create a document library in the same area and add a new field called “Country” and set it to be a lookup field on “CountryList”, column “value”.
• Add a few documents in this library and then follow the steps detailed in the url link provided above to ensure that the document is indexed and advanced search allows you to search specifically on “Country”.
• Go back to the document library and view the properties of the document.
• The properties page shows the various meta data for the particular file, eg Country="United States of America"
• Now click on the file name to open
• Within Word select File -> Properties
• Within the popup select the "File Properties" button at the bottom
• Click on the Custom tab and you should see all the custom properties in Word
• The thing to note is that Word stores the values for lookup fields - not as the string value but as the id, in the example above – Country has the value “209” denoting the “United States of America”. This is because the US is the 209th item in the CountryList Custom List.

Hence when you use the advanced search and select "Country" and then "contains", and then entering "America" will not return any results. You need to instead use the value "209" to return all documents where the Country is the United States of America.

This is a limitation of the Advanced Search feature, which is not usually documented. The advanced search of meta data will work for all text entered fields but not the same way for list lookup fields.

Wednesday, February 22, 2006

The magic URL

If you have an erroneous webpart, SharePoint in its infinite wisdom displays an error message page, but does not provide a listing of webparts to allow you to remove the broken one. Adding "?contents=1" to the end of any page address in SharePoint will display a listing of all webparts on the page with the ability to delete individual ones or all of them.

Making a List Template available in all Areas of the Portal

While SharePoint lets you create templates for any content group like Document Libraries and Lists, it does not let you easily have it accessible from all areas of the Portal. If you create a list in the Home Area and then save it as a template you can only use it in the Home Area - which is quite pointless.

The following is a workaround which will let you add any list template to be accessible from all areas.

1. Create your list in any area and customise it as required. Once you are happy with it save it as a template. In the Title field call it "My List Template - Area Name". Adding the area name is important so you can distinguish it later.

2. Once the template has been saved, click to view the List Template Gallery and then download the template to your local machine - and a .stp file would be saved.

Now repeat the steps below for each area where you want the template to appear.

3. Create a new List - any list will do - and save it as a template - call it "My List Template - Area Name".

4. Once the template has been saved, click to view the List Template Gallery. Click to upload template and in the file select box select the .stp file you saved in step 2. When prompted for a name - give it the same name as in Step 4.

This will then overwrite the dummy template you created in each area with the custom template you created in step 1. You can now use this template in every area where you have added it in.

Tuesday, February 21, 2006

Making a WSS site template appear in SPS Template Selection

One of the features of Windows SharePoint Services is the ability to create a team site and customise it with custom views, meta data, web part pages etc and then to be able to save it as a template for re use. To save a WSS Site as a template,
1. In WSS, click “Site Settings”, “Go to Site Administration” and then “Save Site as Template”
2. Enter the following
  • Filename: Any name you choose – eg “MyCustomSite” – WSS will automatically add a .stp extension.
  • Template Title: A title to make it easy for your users to identify – eg “Custom Site Template”
  • Template Description (optional): Further info as required – “Use this template to create a new team site.”
  • Choose whether you wish to include content or not.
  • Note that Content Editor Webparts always get saved with their content irrespective of your choice.
  • Click OK

3. Click through to “Site Template Gallery” on the next page and your template now appears in the listing.

This template however can only be used to create WSS sites below the current WSS Sites. The template does not appear in SharePoint Portal Server in the “Create a Site” section. To make your template appear in SharePoint Portal Server
1. Right click on the Name and save the .stp file to your local file system.
2. You need to now connect to the SharePoint Portal Server machine and via Command Prompt navigate to \Program Files\Common Files\Microsoft Shared\web server extensions\60\BIN
3. Run the following command
Stsadm –o addtemplate –filename MyCustomSite.stp –title “Custom Site Template” –description “Use this template to create a new team site"
Note: Description is optional
4. This command needs to be followed by iisreset and your “Custom Site Template” should appear in the SharePoint Portal Sites Directory area when you create a new site.

Related CommandsStsadm –o enumtemplates
This lists all the templates that have currently been installed on the server
Stsadm –o deletetemplate –title “Custom Site Template”
This removes any previously installed template. Please note that if you delete a template then any sites that have been created based on it will fail.