Nick Grattan's Blog

About Microsoft SharePoint, .NET, Natural Language Processing and Machine Learning

Posts Tagged ‘SharePoint

Am I Serviced Packed?

with one comment

You can find the current version number for MOSS 2007 through Central Administration:

  • Run Central Administration.
  • Click the Operations tab.
  • Click Servers in farm under the “Topology and Services” section.

This shows the version number for the farm and each individual server in the farm:


Here are the version numbers for various MOSS 2007 service packs:

Unservice packed
MOSS Service Pack 1 (SP1)
MOSS Service Pack 2 (SP2)

For a full list of version numbers, including interim builds see here.

Update: 5 Nov 2009: See here for how to find MOSS 2007 and Windows SharePoint Services version numbers.

Written by Nick Grattan

September 1, 2009 at 4:08 pm

Microsoft SharePoint Designer Download Now Free!

leave a comment »

Written by Nick Grattan

April 24, 2009 at 9:26 am

Code for Creating New Documents based on a content type and template

with 16 comments

This method “CreateDocument” will create a new document in a SharePoint document library using a content type. It will copy the document template associated with the content type into the new document:

// Creates document in given list (root folder).
// Returns true if the file was created, false if it already
// exists or throws exception for other failure
protected bool CreateDocument( string sFilename,
                string sContentType, string sList)
        SPSite site = SPContext.Current.Site;

        using (SPWeb web = site.OpenWeb())
            SPList list = web.Lists[sList];
            // this always uses root folder
            SPFolder folder = web.Folders[sList];
            SPFileCollection fcol = folder.Files;

            // find the template url and open
            string sTemplate =
            SPFile spf = web.GetFile(sTemplate);
            byte[] binFile = spf.OpenBinary();
            // Url for file to be created
            string destFile = fcol.Folder.Url + “/” + sFilename;

            // create the document and get SPFile/SPItem for
            // new document
            SPFile addedFile = fcol.Add(destFile, binFile, false);
            SPItem newItem = addedFile.Item;
            newItem[“ContentType”] = sContentType;
            return true;
    catch (SPException spEx)
        // file already exists?
        if (spEx.ErrorCode == -2130575257)
            return false;
            throw spEx;

This code:

  1. Gets a SPSite for the current site collection, and opens an SPWeb for the site.
  2. Gets a SPList for the given list, and then an SPFolder for the root folder in this list. This code always creates the document in the root folder, but the code can easily be changed to place the document in any folder in the document library.
  3. Gets a SPFileCollection for the documents in the folder.
  4. “DocumentTemplateUrl” is used to return the Url of document template associated with the given content type.
  5. Get an SPFile for the document template in spf and open it for binary access using OpenBinary
  6. Add a new document to the folder through the SPFileCollection referenced by fcol.
  7. Get an SPItem for the new document and set the “ContentType” column to ensure it uses the correct content type (it will default to the first content type in the document library).
  8. Update the item and the added file.
  9. The catch section checks for an -2130575257 error, which indicates the file already exists.


Written by Nick Grattan

December 8, 2008 at 10:23 pm

Logging in as a different user

with 7 comments

When using default.master in SharePoint users have the “Sign in as Different User” menu option on the “Welcome” menu to login as a different user. This is useful when testing security etc.

This menu is often removed when customizing sites – clients we find often do not want these options displayed. So how can you add a link to allow this facility for testing?

The “Sign in as Different User” navigates to the /_layouts/AccessDenied.aspx page, which displays thus:


You’ll notice the link “Sign in as a different user”. From the browser status bar you can find the target of this link:


So, it turns out to login as another user you simply need to navigate to:


The standard browser username/password dialog box will be displayed without the “Access Denied” page being displayed to the user.




Written by Nick Grattan

December 3, 2008 at 1:11 pm

Posted in SharePoint Power User

Tagged with ,

Changing Order / Hiding Columns in New / Edit Forms

with 31 comments

The default order of columns in New/Edit forms for lists and document libraries is typically the order they are added. In many cases you may want to change this order, or to remove columns from these forms.

Changing the column order is easy but the method depends on whether you have selected “Allow management of content types” for the list. See below if you have this option selected, otherwise you can:

  1. Open the list and select Settings + List Settings
  2. Select the “Column ordering” link under “Columns”.
  3. Use the “Change Field Order” form to change the order of columns.


You can only hide columns if “Allow management of content types” is selected! So, to hide, for example, the “Title” column you can:

  1. Open the list and select Settings + List Settings
  2. Select Advanced settings
  3. Click Yes for “Allow management of content types” and then click OK.
  4. From the list of content types, select the content type the column appears in, e.g. “Item”.
  5. From the list of columns for the selected content type, select the column (e.g. Title).
  6. Select Hidden and click OK.


Even if you have a single content type, selecting the “Allow management of content types” option does no harm, so this should work in all cases.

Note that when displaying the content type there is a “Column Order” link under the list of columns which can be used to change the order of columns.

In this example, “Title” is a required field, but you can still hide it. The form will allow the item to be created or updated even though a value has not been supplied.

Written by Nick Grattan

December 2, 2008 at 3:57 pm

Posted in SharePoint Power User

Tagged with ,