Wednesday, September 29, 2010

SharePoint Taxonomy Series Featured in SPTechReport

My blog series on SharePoint taxonomy (SharePoint Enterprise Metadata Management) has been featured in this week’s SharePoint Tech Report newsletter.

This e-mail newsletter is free and you can sign up quickly by visiting the SD Times website.

SPTechReportBanner

Friday, September 10, 2010

SharePoint Incompatible Web Part markup detected

I was working on my Game of Life SharePoint 2010 taxonomy sample, when I suddenly started to get this error message when I tried to add my web part to a page:

“Incompatible Web Part markup detected. Use *.dwp Web Part XML instead of *.webpart Web Part XML.”

image

The problem is that the .NET framework web part and SharePoint web parts are not the same thing. If you’re deriving your web part from System.Web.UI.WebControls.WebParts.WebPart, then you are using the .NET web part. But if you’re using Microsoft.SharePoint.WebPartPages.WebPart, then it’s a SharePoint web part.

As far as I can tell, you can actually use either one inside SharePoint, but there are differences in the way that you code them. If you’re using a SharePoint web part, then you should have a .dwp file in your feature. If you’re using the .NET class, then it should be .webpart. The error about the web part markup occurs when you try to use the wrong one. The .dwp and .webpart files are both XML, but they use a different schema. So if you change from one to the other, you can’t just rename the file, you have to re-write it.

I don’t know why my project suddenly decided that it didn’t want to work. As far as I can remember, all I did was change the assembly version number, but anyway…

To resolve the issue, I had to ensure that I was consistent across my project. I want to use the .NET webpart class, so this is what the beginning of my webpart.cs file looks like. I’ve used the long format for the WebPart class to make things crystal clear:

using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

//Added references
using System.Xml.Serialization;

namespace GameOfLifeWebPartProject.GameOfLifeWebPart
{   
[ToolboxItemAttribute(false)]  [DefaultProperty("Text"), ToolboxData("<{0}:GameOfLifeWebPart  runat=server></{0}:GameOfLifeWebPart>"), XmlRoot(Namespace = "GameOfLifeWebPart")]
public class GameOfLifeWebPart :
System.Web.UI.WebControls.WebParts.WebPart
    {

Now that I’ve clarified which type of web part I’m using, any custom properties that I add have to be in the correct format for that type of web part. If you add custom properties using the other format, the project may compile and deploy, but the properties won’t appear in the web part property pane.

// Custom web part property for the term group name
private string m_termStoreGroupName = "Game of Life";
[System.Web.UI.WebControls.WebParts.WebBrowsable(true),
System.Web.UI.WebControls.WebParts.WebDisplayName("Term Store Group Name"),
System.Web.UI.WebControls.WebParts.WebDescription("The name of the term store group you'll use."),
System.Web.UI.WebControls.WebParts.Personalizable(
System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared),
System.ComponentModel.Category("Game of Life Settings"),
System.ComponentModel.DefaultValue("Game of Life")]
public string TermStoreGroupName
{
     get { return m_termStoreGroupName; }
     set { m_termStoreGroupName = value; }
}

This is what the same property would have looked like if I was using .dwp and the SharePoint web part class:

private string m_termStoreGroupName = "Game of Life";
[Category("Game of Life Settings")]
[WebPartStorage(Storage.Personal)]
[FriendlyNameAttribute("Term Store Group Name")]
[Browsable(true)]
[Description("The name of the m_group you'll use in your term store.")]
[DisplayName("Term Store Group Name")]
[XmlElement(ElementName = "TermStoreGroupName")]
public string TermStoreGroupName
{
     get { return m_termStoreGroupName; }
     set { m_termStoreGroupName = value; }
}

If you decide to change from .webpart to .dwp or vice versa, you’ll need to add the new file to your project and also update the feature package. If you don’t add the new file to the feature package, your web part won’t appear in the web part gallery because it requires that XML file.

Thursday, September 09, 2010

SharePoint Game of Life Web Part on CodePlex

Earlier this year, I presented a session at SharePoint Saturday New York on the new SharePoint 2010 taxonomy features (Enterprise Metadata Management). At the time, I offered to provide the source code for the visual web part sample I used in the developer portion of the talk.

The sample is a simple SharePoint 2010 visual web part based on John Conway’s Game of Life cellular automaton. I wrote about the SharePoint Game of Life web part previously on this blog. If you’re interested in SharePoint taxonomy, you can also check out my blog series on Enterprise Metadata Management (EMM).

The idea is that each term in the SharePoint taxonomy term store represents an organism. As you run through each generation, terms are added and deleted based on the parameters of the simulation.

image

It took a few months, but I’ve cleaned it up, added better error handling and uploaded the code to the SharePoint 2010 Game of Life Web Part project on CodePlex. This project is written in C#. It requires Visual Studio 2010 and SharePoint 2010 Server.

The Long Tale: This SharePoint 2010 taxonomy sample is actually a port of an old-school ASP code sample that I wrote in 1999 for the NCompass Resolution API. Resolution went on to become Microsoft Content Management Server (MCMS).

image

Wednesday, September 01, 2010

Visual Studio Designer View Doesn’t Work After Adding a Table

I’ve been working to clean up my SharePoint Game of Life web part so that I can give it out publicly. I found recently that when I added an ASP.NET  Table control to an ASCX page, I could no longer select the individual controls on the page. This is annoying since I you can’t quickly get to their property grids.

In the Visual Studio designer view, I could only select the Table control that now encompassed all of the other controls.  If I clicked on anything, it just selected the large table. The other ways of selecting nested controls that I would use with WinForms don't work either.

image                         - after adding the table, only the whole table could be selected

After messing about, I found the solution. Since I don't actually need the main table to be a Table control, all I had to do was change it to a simple HTML table. So instead of <asp:Table><asp:TableRow><asp:TableCell>…. I used: <table><tr><td>…

Now the designer is usable again!

image                                                  - after removing the ASP Table control, controls are accessible again