Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 953449 - Last Review: October 17, 2008 - Revision: 1.0
The upgrade schema does not consider the v3Type attribute when you upgrade SharePoint Portal Server 2003 customizations to SharePoint Server 2007
Consider the following scenario. You upgrade a custom list from Microsoft Office SharePoint Portal Server 2003 to Microsoft Office SharePoint Server 2007. Or, you upgrade a custom list from Windows SharePoint Services 2.0 to Windows SharePoint Services 3.0. In this scenario, the
v3Type attribute for the custom list in an upgrade definition is not considered. Therefore, the upgraded custom list has an incorrect content type.
Because of a design limitation, the SharePoint upgrade process does not read the
v3Type attribute for custom lists.
To work around this problem, follow these steps:
- Determine the custom lists that require a reset of the content type.
- Add the content type that you want to the custom list.
- Examine each item in the custom list, and then edit its properties in order to set the content type to the content type that you want.
You can also use the SharePoint object model to create a script that corrects the content type. Specifically, you can use the following code sample to correct the content type:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
namespace FixContentType
{
class Program
{
static void Usage()
{
Console.WriteLine("Usage:");
Console.WriteLine("\tFixContentType.exe -url <Web url> -list <list title> -newct <new content type>");
Console.WriteLine("Example:");
Console.WriteLine("\tFixContentType.exe -url http://server_name/sites/site_name -list \"test list\" -newct \"Test Content Type\"");
}
static void Main(string[] args)
{
string sWeb = string.Empty;
string sList = string.Empty;
string sCT = string.Empty;
// Parse command line parameters.
for (int i = 0; i < args.Length; i++)
{
string sInput = args[i];
switch (sInput.ToLower())
{
case "-url":
sWeb = args[++i].ToString();
break;
case "-list":
sList = args[++i].ToString();
break;
case "-newct":
sCT = args[++i].ToString();
break;
default:
Console.WriteLine("Unrecognizable command switch: {0}", sInput);
Usage();
return;
}
}
// All three parameters are required. Therefore, we must make sure that they are all there.
if (sWeb == string.Empty ||
sList == string.Empty ||
sCT == string.Empty)
{
Console.WriteLine("Some swtiches or values are missing!");
Usage();
return;
}
// Make sure that the Web URL is valid.
if (!Uri.IsWellFormedUriString(sWeb, UriKind.Absolute))
{
Console.WriteLine("The supplied web URL \"{0}\" is invalid", sWeb);
Usage();
return;
}
try
{
using (SPSite site = new SPSite(sWeb))
{
using (SPWeb web = site.OpenWeb())
{
SPList list;
// The list may not exist. Therefore, you must check it.
try
{
list = web.Lists[sList];
}
catch (ArgumentException)
{
Console.WriteLine("Error getting list. The list \"{0}\" likely does not exist!", sList);
return;
}
// Make sure that "Allow Content type Management" is enabled in the list. If it is not enabled, enable it first.
if (!list.ContentTypesEnabled)
{
list.ContentTypesEnabled = true;
list.Update();
}
SPContentType contentType;
// Make sure that the content type does exist in the Web.
try
{
contentType = web.AvailableContentTypes[sCT];
}
catch (ArgumentException)
{
Console.WriteLine("Error getting content type. The content type \"{0}\" likely does not exist!", sCT);
return;
}
// The content type should also be added in the list. If it is not added, add it first.
bool typeAdded = true;
try
{
SPContentType testCT = list.ContentTypes[contentType.Id];
}
catch (ArgumentException)
{
typeAdded = false;
}
if (!typeAdded)
{
list.ContentTypes.Add(contentType);
}
// Update 1000 items at one time for performance.
SPQuery oQuery = new SPQuery();
oQuery.Query = "<Query><OrderBy><FieldRef Name=\"ID\" /></OrderBy></Query>";
oQuery.RowLimit = 1000;
do {
SPListItemCollection items = list.GetItems(oQuery);
for (int i = 0; i < items.Count;i++)
{
SPListItem item = items[i];
if (!contentType.Id.IsParentOf((SPContentTypeId) item[SPBuiltInFieldId.ContentTypeId]))
{
Console.WriteLine("Updating list item at: {0}", item.Url);
item[SPBuiltInFieldId.ContentTypeId] = contentType.Id;
item.SystemUpdate(false);
}
}
oQuery.ListItemCollectionPosition=items.ListItemCollectionPosition;
} while (oQuery.ListItemCollectionPosition != null);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error during updating content type: {0}", ex.Message);
}
}
}
}
APPLIES TO
- Microsoft Office SharePoint Server 2007
- Microsoft Office SharePoint Portal Server 2003
- Microsoft Windows SharePoint Services 2.0
- Microsoft Windows SharePoint Services 3.0
| kbexpertiseadvanced kbtshoot kbprb KB953449 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
Be the first to leave feedback, to help others about this knowledge base
article.
(Optional) Name
(Optional)
Public URL Or Email
Comments
No
HTML -- Text Only Please