Wednesday, 18 February 2009

Packaging multiple lists in a single feature

 

The comment at the following site suggests that it is not possible to put multiple lists in a feature.

http://msdn.microsoft.com/en-us/library/ms434306.aspx

Which although is correct, as always Microsoft have another method of doing this.

The procedure is relatively straight forward.

  • Create list
  • Save the list as a template.
  • Save the stp file(s)
  • create a feature in which the Elements.xml file references the stp.

Create List

This is the normal procedure navigate to the create list screen http://yourserver/_layouts/create.aspx

Select Custom List

image 

In the next screen enter the name of the list and description.

You will then be presented with a standard list, go to List Settings

image

Add the additional columns you require.

Save List as Template

When finished select  Save list as template.

and complete the form shown below.

image

Save the stp.

If you go to the List templates (http://yourserver/_catalogs/lt/Forms/AllItems.aspx) your will find your custom list by clicking on the name of the file you will be given the option to save the file. Put this file somewhere safe!

image

At this point to prevent trying to create two templates of the same name, I usually either rename or delete this item.

Create the feature

For this step I use WSPBuilder which can be downloaded from here.  I assume that you can create a basic feature using the WSPBuilder Add-in.

You will need a file structure like this.

image

Then the elements.xml contents will look like this.

image

The Property Value is the name of the list (News Articles in the example above)

You can nest multiple “Module” elements.

The when you build and deploy the wsp you will have a new feature, which when activated will have additional items in the List templates and in the create list screen.

Saturday, 14 February 2009

No Parameterless Constructor defined for the Object

So we had created a new Web Part and using SharePoint Designer we put it on to a pagelayout, then deployed as a Feature.

Fantastic

Then when creating a page based on the layout we got this error "No Parameterless Constructor defined for the Object"

So a bit of digging on the internet (and reading the error message) we discover that the problem can be caused by the Web Part not having a Constructor without any parameters.

Something like this.

namespace WebPart1
{
[Guid("4547a00e-f630-4117-922e-f075866be9ec")]
public class WebPart1 : System.Web.UI.WebControls.WebParts.WebPart
{
public WebPart1()
{
}
}
}


However the code did have a parameterless constructor. So I spent the next couple of hours adding parameterless constructors to all of the class files.

Unfortunately this was still to no avail.

Eventually I got to the point when I uninstalled the feature, then completely into Central Admin, retracted the solution, then deleted it.

Then deleted the feature folder in the 12 hive (c:\Program Files\Common Files\Microsoft Shared\web server extensions)

Then re-installed the feature et voila!

So I suspect SharePoint had done some caching along the way, and it was only by doing an uninstall was this error cleared from it's cache.

Friday, 13 February 2009

What a week

So it has been one hell of a week, but it is almost over now.

I have started looking at passing the ASP.NET 3.5 exam.

Also had a look at Ruby for the first time.

I am sure you can imagine the amount of cursing that was going on.