You cannot customize permission levels in a web site with inherited permission levels. at Microsoft.SharePoint.SPRoleDefinitionCollection.Add(SPRoleDefinition role)

Okay simple solution here: Make sure that if you are not the root SPWeb and you want to add custom role definitions i.e. SPRoleDefinitions call SPRoleDefinitionCollection.BreakInheritance(bool,bool)

if (!web.IsRootWeb && !web.HasUniqueRoleDefinitions)
      web.RoleDefinitions.BreakInheritance(true, false);
Tagged ,

Server Out Of Memory – There is no memory on the server to run your program. Please contact your administrator with this problem. at Microsoft.SharePoint.Library.SPRequestInternalClass.ApplyWebTemplate(String bstrUrl, String& bstrWebTemplate, Int32& plWebTemplateId)

There are lots of reasons this error message can occur, see: In my case it happened when a new site was being provisioned using a custom site definition during the ApplyWebTemplate call.

Turned out the there were subtle errors in my onet.xml. In particular I was referencing some document templates using an incorrect path:

<Project Title="$Resources:onet_TeamWebSite;" xmlns=""  Revision="2" ListDir="$Resources:core,lists_Folder;" xmlns:ows="Microsoft SharePoint">
    <DocumentTemplate Path="INCORRECTPATH" Name="" 
Tagged , ,

Lookup the Netbios name of a domain using directory services

Okay so its pretty easy to get the fully qualified domain name (FQDN).

using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;


But what happens if you want to get the old-skool netbios name. The quickest way is to use System.Environment:

using System


This gets the network domain name associated with the current user. So not much good if your code is running as a service that could well be configured to run at Network Account. Surely you can do this using DirectoryServices? Bit of Googling and coding and we have a nice little extension method which does just that

/// <summary>
    /// Defines extentions made to the <see cref="Domain"/> class.
    /// </summary>
    public static class DomainExtensions
        public static string GetNetbiosName(this Domain domain)

            // Bind to RootDSE and grab the configuration naming context
            DirectoryEntry rootDSE = new DirectoryEntry(@"LDAP://RootDSE");
            DirectoryEntry partitions = new DirectoryEntry(@"LDAP://cn=Partitions," + rootDSE.Properties["configurationNamingContext"].Value);

            DirectoryEntry domainEntry = domain.GetDirectoryEntry();

            //Iterate through the cross references collection in the Partitions container
            DirectorySearcher directorySearcher = new DirectorySearcher(partitions)
                    Filter = "(&(objectCategory=crossRef)(ncName=" +
                             .Replace("LDAP://", string.Empty)
                             .Replace(domain.Name + "/", string.Empty) + "))",
                    SearchScope = SearchScope.Subtree


            //Display result (should only be one)
            SearchResultCollection results = directorySearcher.FindAll();
            if (results.Count == 0)
                return null;

            return results[0].Properties["nETBIOSName"][0].ToString();



Note You can also retrieve the netbios entry using netapi32.dll

Tagged , , ,

SharePoint field constants.

I always forget the name of the class that stores a great big list of field ID constants. So as a reminder to myself it’s SPBuildInFieldId

For example:

SPFieldUserValue user = item[SPBuiltInFieldId.Author]

Whilst looking this up again I stumbled across another similar class SPBuiltInContentTypeId that holds content type id’s for the common OOTB content types, neat!

if (this.ContentTypeId.IsChildOf(SPBuiltInContentTypeId.Message))
Tagged , , , , ,

How to serialize List using XML serialization

Okay so this one is filed under the “I keep looking up the same things” category. In .Net 1 lists of objects were commonly serialized either using an Array or an ArrayList property:

/// <summary>
/// List Item permissions to be given to this group
/// </summary>
[XmlArray("ListItems"), XmlArrayItem("ListItemPermissions", typeof(ListItemPermissions))]
public ArrayList ListItems
        get { return _listItems; }
        set { _listItems = value; }
public Group[] Groups
        get { return this.groups; }
        set { this.groups = value; }

In .net 2.0 List<T> can be serialized by adding the XmlArray attribute in the property declaration, as follows:

public List<PortalAudience> Audiences { get; set; }


Tagged , ,

Quicklaunch navigation will not show a link if it’s set as the home page.

Today I had the requirement to include a link in the quick launch menu to the current web’s homepage. Agreed it’s a strange requirement, but nonetheless in this case it was arguably not too bad.

However the default SPNavigationProvider does not display the homepage in the quick launch menu. In order to do this add the link as an external page, even though it’s not.

using (SPSite site = new SPSite("http://localhost"))
	using (SPWeb web = site.OpenWeb(""))
		string url = web.ServerRelativeUrl + "/Pages/MyPage.aspx";
		WL("Adding..." + url);
		SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;				
		SPNavigationNode newNode = new SPNavigationNode("MyLinkTitle", url, true);
Tagged , , , , ,

Visual Studio 2008 SP1 Crashes when exiting the application, in module ModName:msenv.dll

After recently increasing my monitor setup to 3 flat screens! I decided to embark on the ultimate 2-window Visual Studio layout, docking most of my non-text editor windows on monitor 2. After lots of precision placements of windows, I thought I had better close Visual Studio so that it saves my new layout. Well fat chance!

Visual Studio threw up the depressing “Microsoft Visual Studio has encountered a Problem and needs to close.”

Microsoft Visual Studio has encountered a problem and needs to close


For a laugh I decided to fire off the error report via the “Send Error Report” button. The subsequent confirmation button had a link on it which I almost missed.

Visual Studio 2008 Send Error Report


Clicking on this link took you to a rather generic looking Windows Error Reporting page:

Windows Error Reporting Page

However out of curiosity I followed the link to the KB article, expecting it to be next to useless in solving my issue. However imagine my surprise when the article was 100% relative!

KB 960075 Fixes issues with Visual Studio 2008 SP1 IDE crashes when changing the window layout. Hooray for Windows Error reporting, it actually works {on incredibly rare occasions}.


UPDATE: I ended up reading the comments on before installing the hotfix and “Window->Reset Window Layout” fixed the crashes for me. In the end I didn’t bother to install the hot fix.


2nd UPDATE: Okay so I *DID* have to install it in the end, and it worked fine.

Tagged , ,

Shared Services User profile synchronization with WSS user profiles stored in the User Information list

Ever wished that the WSS user profile would update it’s values immediately after you’ve just ran a new SSP profile import. Well I just came across a very cool little tool that does just that. The “User Profile Sync” tool hosted on codeplex.

It’s worth noting that SharePoint has timer jobs that run and perform this synchronization process for you. Hover the above mentioned tool allows you to force this process to occur immediately.

Tagged , ,

Target Audience property not displaying / missing for web parts

I came across this problem on a web application that had been working fine, then all of a sudden the “Target Audiences” property disappeared from the web part tool pane.


To solve this problem I re-associated the web application with the Shared Service Provider (SSP) and bounced IIS.

1. Web applications are associated with SSP’s in central administration. Select Shared Services Administration

sharepoint central administration


2.  Select Change Associations

sharepoint central administration manage farm shared services


3. Select the web application you are having problems with, and select OK to complete the process.

sharepoint central administration change association between web applications and ssps

4. Perform a  complete IISReset.

Then the property miraculously reappeared – hooray!

Pages - AllCounterParties - Mozilla Firefox (3) ITS BACK!!


During investigating this issue I found the class responsible for rendering this section of the tool was an internal class WebPartToolPartAdvanced. I you really get stuck and my method doesn’t cut it you could dig around in that class and see if you can find anything that helps.

Tagged , , , ,

Unknown SPRequest error occurred. More information: 0x80040e14 – Exception from HRESULT: 0x80040E14

If you get ever get this error message and you are rolling out your own list definition, chances are you messed something up in the shema.xml file.

The first place to look is the event logs. In my case today this was caused due to an incorrectly mapped column name in the field element. The log files gave the clue:

Unexpected query execution failure, error code 8143. Additional error information from SQL Server is included below. "Parameter '@sql_variant1' was supplied multiple times." Query text (if available): "SET NOCOUNT ON; DECLARE @ItemId int,@@iRet int,@ExtraItemSize int,@DN nvarchar(256),@LN nvarchar(128),@@S uniqueidentifier,@@DocUIVersion int,@@Level tinyint;SET @@S='846FD34D-3722-433D-845B-564ACB4037EE';SET @@Level=1;SET @@DocUIVersion = 512;BEGIN TRAN;SET @ItemId=NULL;SET @DN=N'counterparty/Lists/CounterParties';SET @LN=NULL;SELECT @ExtraItemSize = 0  EXEC @@iRet = proc_AddListItem @SiteId = '846FD34D-3722-433D-845B-564ACB4037EE',@WebId='EEFB7523-73C9-4BDF-B2FC-9AA940A0B059',@ListID = 'B6BA34B0-8CBE-4F1F-819C-0460CF82FA35',@RowOrdinal = 0,@ItemDocType = 0,@ItemId = @ItemId OUTPUT,@ItemDir...	 

I had used sql_variant1 twice for the ColName attribute, replacing the duplicate with sql_variant2 did the trick 🙂

Tagged ,