Saturday, 27 October 2012

How to Programmatically Approve documents in Sharepoint

Hi,

A requirement was posted to me where a developer wanted to approve the documents programmatically. I shared the code snippet below and it the logic worked out. I am sharing it here again:

using
(SPSite site = new SPSite("YourSiteUrl"))

{
using(SPWeb web = site.OpenWeb())

{
SPFolderCollection folders = web.Folders;

SPFolder folder = folders["DocumentLibraryName"];

SPFile file = folder.Files[itemIndex];

file.CheckIn("CheckInComment", SPCheckinType.MajorCheckIn);

file.Approve("Approved");

web.Update();

}

}

This code snippet can be modified in the way desired.

Thanks,


Rahul Rashu
 

No comments:

Post a Comment