Created
December 12, 2013 10:47
-
-
Save vgrem/7926168 to your computer and use it in GitHub Desktop.
Publishing Web Client Object for SharePoint 2010 (CSOM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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