SharePoint problem: moderation comment is not saved

I solved last week one pretty cool mystery in SharePoint. I have form that users use to make some specific changes to list items. When all the fields on form are filled then user clicks save button. Changes are saved to list item and list item is automatically accepted. Status change is made through ModerationInformation property ofSPListItem. Everything seemed to work except one little thing – moderation status comment was not saved.

It took me couple of hours to figure out what is going on. This time, again, Reflectorsaved my ass. I followed the method calls from list item update to SPRequest methods (find out more by reading brilliant code posting Understanding SharePoint: SPRequestby Hristo Pavlov) that Reflector wasn’t able to disassemble. As soon as I saw request I got the correct answer: Response.

Take a look at this code fragment.


// initialization code

item.ModerationInformation.Status =
SPModerationStatusType
.Approved;
item.ModerationInformation.Comment =
"Accepted"
;
item.Update();

// some more code

Response.Redirect(returnUrl,
true);

You see that Response is forced to end using second argument ofResponse.Redirect() method. This was the source of problem. After using Response.Redirect with one argument the problem was solved because Response was not forced to end.

I hope this information saves some hours of work for world. 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *