I am an administrator/developer and I have created a news site publishing site and all everything in the "Master Page Gallery" Needs to be approved. First I tried to use 'PublishingSite.PageLayouts' objects but it does not return hidden files or folders.

I am having no issue approving Items/Files with

   foreach( SPListItem item in masterGalList.GetItems()){
         if( item.ModerationInformation== SPModerationStatusType.Draft)
         If( item.ModerationInformation == SPModerationStatusType.Pending)

But Approving Folders with the UI I get an error (Needs to accomplished with c#)

   "ERROR:  The file ... has been modified by (unkown) on ..."

The code for approving Folders is

 Foreach( SPFolder folder in MasterGalList.RootFolder.SubFolders){
        folder.Item.ModerationInformation.Status= SPModerationStatusType.Approve;
        folder.Item.ModerationInformation.Comment= "comment";

Then if I go look at the list the folder will be missing. Anybody know what's wrong?

1 Answer 1


In the feature of your module :
•Create an event Receiver •Add this code :

public override void FeatureActivated(SPFeatureReceiverProperties properties)   

private void publishItemStyle(SPFeatureReceiverProperties properties)   
        SPWeb web = (SPWeb)properties.Feature.Parent;  
        SPFile file = web.GetFile("Style Library/Xsl Style Sheets/ItemStyle.xsl");  

        if (file.Level == SPFileLevel.Checkout)  
          file.CheckIn("", SPCheckinType.MajorCheckIn);  
        if (file.Level == SPFileLevel.Draft)  
           if (file.DocumentLibrary.EnableModeration) file.Approve("");  
            else file.Publish("");  
    catch (Exception e)  



try seperating the process:

Foreach( SPFolder folder in MasterGalList.RootFolder.SubFolders)
   SPModerationInformation moderationInformation = folder.Item.ModerationInformation;       
   moderationInformation.Comment = string.Format("approved {0}",DateTime.Now);         
   moderationInformation.Status = SPModerationStatusType.Approved;        
  • My code to approve files works fine. And I do take the correct approch for approving folders, but something else must be wrong as the folders disappear
    – user13186
    Apr 17, 2013 at 15:12
  • just added an edit, Iv changed it so that its using the SPModerationInformation instead of directly using it through the SPFolder! you need to do it through the list item itself that you are doing ;)
    – Ali Jafer
    Apr 17, 2013 at 15:31
  • Thank you for the help! But that has the same results, if the issue was with the approval code I would be able to approve using UI but I still can't.
    – user13186
    Apr 17, 2013 at 16:44
  • Currently chasing the route of delete all items and recreate based on another site collection
    – user13186
    Apr 17, 2013 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.