Pages

IMG

[SharePoint 2010 - Developpement] Publish and approve file programmatically sharepoint 2010

vendredi 1 juillet 2011

I created a module which deploy a file (itemStyle for a ContentQueryWepPart), and i wanted to publish and approve it directly programmatically.
In the feature of your module :
  • Create an event Receiver
  • Add this code :
   1: public override void FeatureActivated(SPFeatureReceiverProperties properties)
   2: {
   3:     publishItemStyle(properties);
   4: }
   5:  
   6: private void publishItemStyle(SPFeatureReceiverProperties properties)
   7: {
   8:     try
   9:     {
  10:         SPWeb web = (SPWeb)properties.Feature.Parent;
  11:         SPFile file = web.GetFile("Style Library/Xsl Style Sheets/ItemStyle.xsl");
  12:  
  13:         if (file.Level == SPFileLevel.Checkout)
  14:             file.CheckIn("", SPCheckinType.MajorCheckIn);
  15:         if (file.Level == SPFileLevel.Draft)
  16:         {
  17:             if (file.DocumentLibrary.EnableModeration) file.Approve("");
  18:             else file.Publish("");
  19:         }
  20:         file.Update();
  21:     }
  22:     catch (Exception e)
  23:     {
  24:     }
  25: }

Hope this help,

Aucun commentaire:

 

Blogroll

Jeff ANGAMA, is Office 365 / SharePoint Consultant. Started on MOSS2007 - More Infos Here -

RSE

Rechercher dans ce blog

Where Users are from ?