Monthly Archives: December 2009

SharePoint custom workflow activity. “Failed to load toolbox item. It will be removed from toolbox.”

I was getting this error message in Visual Studio 2008 when adding a custom activity to an existing workflow.

 

Solution

This worked for me, your mileage, may and probably will vary.

It was necessary for me to un-gac the workflow project, then the custom activities could be added to the design surface as expected.

Tagged , , , , ,

Safe mode did not start successfully. Could not load file or assembly

Ever get any of these errors?

WindowClipping (17)

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

Tagged ,

Programmatically determine is a feature is activated or even installed

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;
    }
}
Tagged , , ,

The imported project “C:\Program Files\MSBuild\Microsoft.Office.InfoPath.targets” was not found

If you get this error message, which I did this morning opening up someone else’s SharePoint solution, make sure you have InfoPath installed.

Microsoft Visual Studio

 

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

Microsoft Office Enterprise 2007

Tagged , ,

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: 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="" 
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;

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

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; }
}
....
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; }

…..

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);
		nodes.AddAsLast(newNode);
		web.Update();
	}
}
Tagged , , , , ,