Sunday, July 26, 2009

How to: Create List Instance using WSPBuilder

Hi all,

In the blog post, I will cover how to create a list instance using WSPBuilder. There are few small points to be noted.

Step1: Create a WSPBuilder project called as ListInstance.
















Step2: Right-click on project >> Add new item >> Choose Feature with Receiver element from WSPBuilder called as "ListInstanceReceiver"







Step3: In ListInstanceReceiver, create a list instance. Now, if you create a new Guid for "FeatureID", you will get an error. Lets create a new Guid for FeatureID (Tools >> Create Guid)


<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<ListInstance

Title="My list instance"

Url="Lists/MyListInstance"

OnQuickLaunch="TRUE"

QuickLaunchUrl="Lists/MyListInstance"

TemplateType="100" FeatureId="efca61a1-7f3f-4f8f-9515-e831008cba15'">

</ListInstance>

</Elements>



Step4: Build the solution, Build WSP and Deploy.















Step5: Go to the Site actions >> Site settings >> Site Features >> Activate the "ListInstanceReceiver". You will get this error:


Feature 'efca61a1-7f3f-4f8f-9515-e831008cba15' for list template '100' is not installed in this farm. The operation could not be completed.


Apparently, FeatureId: This is the ID of the feature in which the base list template is defined.

Therefore, we have to use pre-defined FeatureId.


Hence, we need to use "00BFEA71-DE22-43B2-A848-C05709900100" as our list is a generic list. Now, we have the upgrade our solution.


You can get all available list templates with their template type id and their corresponding feature id here.


When you again activate the feature, you will still get an error as follows:


The method or operation is not implemented.


We just need to remove the line throw new Exception("The method or operation is not implemented.");
in all the methods 

FeatureActivated,
FeatureDeactivating,
FeatureInstalled,
FeatureUninstalling


Therefore the ListFeatureReceiver.cs will look this

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
}

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{
}


Compile and upgrade the solution.








Cheers,
Aroh

Download the code here.

4 comments:

Ashok said...

Hi Aroh,

Everything works fine until you state:

We just need to remove
FeatureActivated,
FeatureDeactivating,
FeatureInstalled,
FeatureUninstalling
throw new Exception("The method or operation is not implemented.");


So what code do we replace it with please exactly?

Thanks in advance, Ashok

Aroh said...

Hi Ashok,

I guess, I have not clearly mentioned where to remove the override methods " throw new Exception("The method or operation is not implemented.");"
.....

What you have to remove this line in all methods i.e. FeatureActivated,
FeatureDeactivating,FeatureInstalled,
FeatureUninstalling etc.

For an instance, for the methods

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
}

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
}

public override void FeatureInstalled(SPFeatureReceiverProperties properties)
{
}

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
{ }

I have already provided the sample download-able sample as well in the blog post.

I hope it will help you.
Cheers,
--Aroh

Anonymous said...

Hi Aroh,

It works perfectly now! Thank you very much indeed for replying so quickly.

Best Wishes,

Ashok

Aroh said...

My pleasure :)

How to display Sharegate administrative dynamic reports via Power BI on SharePoint Online

After working in the SharePoint domain for a couple of years as SharePoint consultant , I am fortunate enough to help customers from man...