Benutzer:MovGP0/SharePoint/Publishing

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      


Enable Publishing Feature

[Bearbeiten | Quelltext bearbeiten]
Site Collection Site

→ Site Settings
→ Site Collection Administration
→ Site collection features
→ Office SharePoint Server Publishing Infrastructure
→ Activate

→ Site Settings
→ Site Administration
→ Site features
→ Office SharePoint Server Publishing
→ Activate

Check if item is published

[Bearbeiten | Quelltext bearbeiten]
SPListItem item = list.GetItemById(99);
bool IsPublished = (item.Versions[0].Level == SPFileLevel.Published)

Registering an EventHandler on publishing

[Bearbeiten | Quelltext bearbeiten]
[LogException]
public override void ItemUpdating(SPItemEventProperties properties)
{
   base.ItemUpdating(properties);
   if (properties.ListItem == null)
      return;
   
   var item = properties.ListItem;
   if (IsItemPublishing(item))
   {
      OnItemPublishing(item);
   }
}

private bool IsItemPublishing(SPListItem item)
{
   var iBefore = Convert.ToString(properties.BeforeProperties["vti_level"]);
   var iAfter = Convert.ToString(properties.AfterProperties["vti_level"]);

   return (item.Level == SPFileLevel.Published && iBefore.Equals("1") && iAfter.Equals("1"));
}

private void OnItemPublishing(SPListItem item)
{
   // ...
}
enabling Versioning
enabling Moderation & Approval
find approved and published versions of an Item
if (documentList.EnableModeration && documentList.EnableVersioning)
{
   foreach(var item in documentList.Items)
   {
      if(item.ModerationInformation.Status != SPModerationStatusType.Approved) continue;

      var allVersions = item.Versions;
      foreach (SPListItemVersion version in allVersions)
      {
         if (version.Level == SPFileLevel.Published)
         {
            yield return version.ListItem;
         }
      }
   }
}