file.Approve(string.Format("This file has been approved the {0}", DateTime.Now));
If you want to approve a folder, it seems obvious that an Approve method also exists in the SPFolder class. Unfortunately, it is not the case. you have to use the ModerationInformation property of the underlying SPListItem:
using (SPSite site = new SPSite("http://server:port/"))
{
SPWeb web = site.OpenWeb();
using (web)
{
SPList myList = web.Lists["MyList"];
SPFolder newFolder = myList.RootFolder.SubFolders.Add("folderName");
SPModerationInformation moderationInformation = newFolder.Item.ModerationInformation;
moderationInformation.Comment = string.Format("This folder has been approved the {0}",DateTime.Now);
moderationInformation.Status = SPModerationStatusType.Approved;
newFolder.Item.Update();
}
}
2 comments:
Thank you for this.
Thanks thats work fine!
Post a Comment