For some reason when I read those first words I throw my hands up and think of the movie Highlander

Yet another pain in the arse error message I hit…[Microsoft.SharePoint.SPException] = {"There can only be one instance of this list type in a web.\n\nAn instance already exists."}

Awhile back when doing some custom list development, I recalled that you could set property to basically say that one and only one instance of your custom list type could exist within a site (Unique=”True”).  See Below for what I am talking about. 

<ListTemplate Name="MyNetworkMembershipList" DisplayName="My 
Network Membership List Template" Type="100" Description="Template 
for My Network Membership Lists" BaseType="0" 
OnQuickLaunch="True" SecurityBits="14" Sequence="410" 
Image="/_layouts/images/itgen.gif" Unique="True" 
DisableAttachments="True" Hidden="False" HiddenList="False" 
FeatureId="{GUID}" />

 

Apparently with blog sites you can’t have both content approval and versioning turned on for a Post list.  Of course the client wanted both turned on, so I turned to writing an event receiver to handle the add/update/delete events so that I could basically create a “version” list that would live behind the scenes for legal purposes.

I started out by writing the event receiver to handle the added/updated/deleted events and to basically take the Post listitem and “copy” a version of it to my version posts list…easy enough.  I then obviously had to add code in my feature event receiver to create the versioned post list if it was already created.  I tried to do the following:

Guid newListId = web.Lists.Add("BlogPostVersioningList", "Blog Posting Version 
List", SPListTemplateType.Post);

Turns out that the list type “Post” is one of those lists in a blog site that is set to be Unique.  I deceided to take a look at the blog site definition and see if I could verify this.  I dug into the 12 Hiv, 12\TEMPLATE\SiteTemplates\Blog\Xml  and opened “onet.xml”.  A few lines down I noticed this line:

 

<ListTemplate 
Name="posts" 
EnableModeration="True" 
DisplayName="$Resources:core,posts_schema_blg_title;" 
Type="301" 
BaseType="0" 
OnQuickLaunch="TRUE" 
FolderCreation="FALSE" 
AllowDeletion="FALSE" 
Unique="TRUE" 
DisallowContentTypes="TRUE" 
SecurityBits="11" 
Description="$Resources:core,posts_schema_blg_description" 
Image="/_layouts/images/itposts.gif"></ListTemplate>

BOOM! Tough Acting Tenactin! As you can see above, “Unique=’TRUE’”, hence the error message I got.

So..now that I know I can have only 1 list of type Post….what the hell am I supposed to do?  Since the columns in the Post list were information that I wanted to keep, I decided to basically create a generic list and then “synch” up the fields between the Post list and my new generic list, resulting in a version list that I could then move my posts to from the SPItemEventReceiver

 
Guid newListId = web.Lists.Add("BlogPostVersioningList", "Blog Posting 
Version List", SPListTemplateType.GenericList);

 

At the end of the day, I now have a feature that creates a “Versioned” Post list and attaches an Item event receiver to move blog posts on add/update/delete over to my “Versioned” Post list for legal purposes.


Posted in:   Tags:
Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2017 Tony Testa's World