December 22, 2009 by Edward Wilde
Ever get any of these errors?
The DataSourceID of ‘TopNavigationMenu’ must be the ID of a control of type IHierarchicalDataSource. A control with ID ‘topSiteMap’ could not be found. at System.Web.UI.WebControls.HierarchicalDataBoundControl.GetDataSource()
at System.Web.UI.WebControls.HierarchicalDataBoundControl.ConnectToHierarchicalDataSource()
at System.Web.UI.WebControls.HierarchicalDataBoundControl.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Troubleshoot issues with Windows SharePoint Services.
Server Error in ‘/’ Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: This page has encountered a critical error. Contact your system administrator if this problem persists.
Source Error:
Line 1: <%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,
Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Reference VirtualPath="~TemplatePageUrl" %>
<%@ Reference VirtualPath="~masterurl/custom.master" %>
Line 2: <html xmlns:mso="urn:schemas-microsoft-com:office:office"
xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
Line 3: <!--[if gte mso 9]><xml>
Source File: /Pages/Default.aspx Line: 1
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Event log error message
Safe mode did not start successfully. Could not load file or assembly ‘MyCompany, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXXX’ or one of its dependencies. The system cannot find the file specified.
Solution
In my case the error message from the event log was spot on. I had accidentally removed a MyCompany assembly from the GAC.
Other errors can also cause the same problem, whilst debugging this issue I came across another blog post that might be of interest: http://www.dotnetmafia.com/blogs/dotnettipoftheday/archive/2008/09/24/safe-mode-did-not-start-successfully-request-failed.aspx
Posted in sharepoint | Tagged debugging, sharepoint | Leave a Comment »
December 17, 2009 by Edward Wilde
Okay so ever needed to see if a particular web or site feature is activated? Well if it’s activated it will be in the SPWeb.Features SPFeatureCollection or SPSite.Features. If it’s not activated it won’t be. Simple.
To check if a feature is installed examine the feature definitions collection on the SPFarm object, below are a couple of little extension methods that demonstrate this concept.
/// <summary>
/// Defines extensions made to the <see cref="SPWeb"/> class
/// </summary>
[CLSCompliant(false)]
public static class SPWebExtensions
{
public static bool IsFeatureActivated(this SPWeb web, Guid featureId)
{
return web.Features[featureId] != null;
}
public static bool IsFeatureInstalled(this SPWeb web, Guid featureId)
{
SPFeatureDefinition featureDefinition = SPFarm.Local.FeatureDefinitions[featureId];
if (featureDefinition == null)
{
return false;
}
if (featureDefinition.Scope != SPFeatureScope.Web)
{
throw new GeneralApplicationException(
string.Format("Feature with the ID {0} was installed but is not scoped at the web level.", featureId));
}
return true;
}
}
Posted in .net, sharepoint | Tagged sharepoint, SPFeature, SPFeatureCollection, SPFeatureDefinition | Leave a Comment »
December 17, 2009 by Edward Wilde
If you get this error message, which I did this morning opening up someone else’s SharePoint solution, make sure you have InfoPath installed.

Once I installed the InfoPath client application with .Net Programmability Support, see below, the targets file was installed to the MSBuild directory.

Posted in development, sharepoint | Tagged infopath, msbuild, sharepoint | Leave a Comment »
December 16, 2009 by Edward Wilde
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);
}
Posted in sharepoint | Tagged sharepoint, SPRoleDefinition | Leave a Comment »
December 15, 2009 by Edward Wilde
There are lots of reasons this error message can occur, see: http://www.google.com/search?q=sharepoint+Server+Out+Of+Memory. 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="http://schemas.microsoft.com/sharepoint/" Revision="2" ListDir="$Resources:core,lists_Folder;" xmlns:ows="Microsoft SharePoint">
...
<DocumentTemplates>
<DocumentTemplate Path="INCORRECTPATH" Name=""
Posted in bugs, sharepoint | Tagged bug, onet.xml, sharepoint | Leave a Comment »
December 14, 2009 by Edward Wilde
Okay so its pretty easy to get the fully qualified domain name (FQDN).
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;
Console.WriteLine(Domain.GetCurrentDomain().Name)
But what happens if you want to get the old-skool netbios name. The quickest way is to use System.Environment:
using System
Console.WriteLine(System.Environment.UserDomainName)
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=" +
domainEntry.Path
.Replace("LDAP://", string.Empty)
.Replace(domain.Name + "/", string.Empty) + "))",
SearchScope = SearchScope.Subtree
};
directorySearcher.PropertiesToLoad.Add("nETBIOSName");
//Display result (should only be one)
SearchResultCollection results = directorySearcher.FindAll();
if (results.Count == 0)
{
return null;
}
return results[0].Properties["nETBIOSName"][0].ToString();
}
}
Usage:
Domain.GetCurrentDomain().GetNetbiosName()
Note You can also retrieve the netbios entry using netapi32.dll http://blog.dotsmart.net/2009/03/11/getting-a-machine%E2%80%99s-netbios-domain-name-in-csharp
Posted in .net | Tagged .net, ActiveDirectory, DirectoryServices, Domain | 1 Comment »
December 14, 2009 by Edward Wilde
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))
{
......
}
Posted in sharepoint | Tagged field, fieldconstant, fieldid, sharepoint, SPBuiltInContentTypeId, SPBuiltInFieldId | Leave a Comment »
December 14, 2009 by Edward Wilde
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; }
}
....
or
....
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:
[XmlArray("Audiences")]
public List<PortalAudience> Audiences { get; set; }
…..
Posted in .net | Tagged list, xml, xmlserialization | Leave a Comment »
December 9, 2009 by Edward Wilde
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);
nodes.AddAsLast(newNode);
web.Update();
}
}
Posted in sharepoint | Tagged navigation, Quicklaunch, sharepoint, SPNavigation, SPNavigationNode, SPNavigationNodeCollection | Leave a Comment »
December 4, 2009 by Edward Wilde
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.”

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.

Clicking on this link took you to a rather generic looking 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 http://code.msdn.microsoft.com/KB960075 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.
Posted in bugs, development, visual studio | Tagged bug, visualstudio, windowlayout | Leave a Comment »