Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)
               item.file.Publish("comment")
         If( item.ModerationInformation == SPModerationStatusType.Pending)
               Item.file.Approve("comment")
    }

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";
        Folder.Item.SystemUpdate(true);
 }

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

share|improve this question
add comment

1 Answer

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

public override void FeatureActivated(SPFeatureReceiverProperties properties)   
{   
     publishItemStyle(properties);   
}   

private void publishItemStyle(SPFeatureReceiverProperties properties)   
{   
    try   
    {  
        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("");  
        }  
        file.Update();  
    }  
    catch (Exception e)  
    {  
    }  
}

http://jeff-sharepoint-note.blogspot.co.uk/2011/07/publish-and-approve-file.html

EDIT

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;        
   folder.Item.Update();
}
share|improve this answer
    
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 '13 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 Sharepoint Apr 17 '13 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 '13 at 16:44
    
Currently chasing the route of delete all items and recreate based on another site collection –  user13186 Apr 17 '13 at 16:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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