Nishand's Blog

Welcome to my personal blog, All the information in this bogs is my ideas,findings and thoughts on .Net, Asp.Net and SharePoint.
ALL POSTING ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND

Updating 'ModerationStatus' field

You might have experienced a road block when trying to the update the ‘ModerationStatus’ field with other fields. Any attempt to do so will result in an exception “You cannot change moderation status and set other item properties at that same time”. This is an expected behavior since the document deals with stream, promotion and demotion and for non document libraries we are not touching the streams, so it allows updating other fields with “ModerationStatus”.

Here is the code: In this sample code, we are trying to update the 'Editor' field along with the 'ModerationStatus’.

      

   1: SPSite oSite = new SPSite("http://localhost:100/sites/Internetsite/");
   2:         SPWeb oWeb = oSite.OpenWeb(); 
   3:         SPList oList = oWeb.Lists["Shared Documents"]; 
   4:         SPListItem oListItem = oList.Items[0]; 
   5:         SPUser oUser = oWeb.AllUsers[@"domain\user123"]; 
   6:         SPFieldUserValue oUserValue = new SPFieldUserValue(oWeb, oUser.ID, oUser.LoginName); 
   7:         oListItem["Editor"] = oUserValue;                
   8:         oListItem.ModerationInformation.Status = SPModerationStatusType.Approved; 
   9:         oListItem.Update();

 

Note: This behaviour is only with libraries of type document libraries(SPBaseType.DocumentLibrary).

Good Luck!!!

Published Saturday, June 07, 2008 5:24 PM by nishandv

Comments

No Comments
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker