Today I was working with some batch code that updates the group permissions of several folders within the Site Collection Documents library. Although the code was calling Update() on the SPListItem after modifying the role assignments, when I would run a report to see all content in need of approval it listed every folder which had just been updated. I would then have to click and go through and approve each folder every time the job was run. Makes for lots of impressive sounding mouse click activity, but it gets boring. So today I wrote a function to set the approval status to Approved by the user running the script. Problem solved, no more frenzy of mouse clicks after every content import.
- private static void UpdateListItem(SPListItem item)
- {
- item.ModerationInformation.Status =
- SPModerationStatusType.Approved;
- item.ModerationInformation.Comment =
- "Approved by automated process. User=" +
- System.Environment.UserName;
- item.Update();
- }