Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created December 12, 2013 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vgrem/7926168 to your computer and use it in GitHub Desktop.
Save vgrem/7926168 to your computer and use it in GitHub Desktop.
Publishing Web Client Object for SharePoint 2010 (CSOM)
namespace SharePoint.Client.Publishing
{
//Publishing Web for CSOM in SharePoint 2010
public class PublishingWeb
{
public PublishingWeb(Web web)
{
this._web = web;
}
public static bool ReturnIsPublishingWebProperty(Web web)
{
EnsureWeb(web);
return GetProperty(web, "__PublishingFeatureActivated", false);
}
private static void EnsureWeb(Web web)
{
var ctx = web.Context;
if(web.AllProperties.FieldValues.Count == 0)
{
ctx.Load(web, w => w.AllProperties);
ctx.ExecuteQuery();
}
}
private static T GetProperty<T>(Web web,string propName, T defaultPropValue)
{
if (!web.AllProperties.FieldValues.ContainsKey(propName))
return defaultPropValue;
return (T)Convert.ChangeType(web.AllProperties[propName], typeof(T));
}
private static void SetProperty<T>(Web web,string propName, T propValue)
{
web.AllProperties[propName] = propValue;
}
private Web _web;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment