DotNetDude
DotNetDude

Reputation: 155

Change ContentType - SharePoint Workflow in VS2008

I need to change the ContentType in my Sharepoint workflow. If I set the following will this change it? If not how. If I am presently using ContentType 1 for a List and want to switch to using ContentType 2 what code do I need in order to make this happen?

SPListItem currentItem = workflowProperties.Item;
SPContentType myCType = workflowProperties.List.ContentTypes["ContentType 2"];

        currentItem["ContentTypeId"] = myCType.Id;
        currentItem.Update();   

I'm thinking this will work but not sure.

Thanks, JJ

Upvotes: 0

Views: 502

Answers (1)

naivists
naivists

Reputation: 33511

Looks fine to me. I would call currentItem.SystemUpdate() in the end, since this leaves the 'modified date' and 'modified by' fields untouched. If you simply call Update, it will show the item as modified by "Sharepoint\system"

Upvotes: 1

Related Questions