When Going to Site settings>Navigation for an subsite i want to modifie The Structural Navigation:Sorting to be the first value (Sort automatically)
I am trying to do this with my code,
ClientContext clientContext;
var navigation = new ClientPortalNavigation(clientContext.Web);
navigation.CurrentIncludePages = true;
navigation.GlobalIncludePages = false;
navigation.OrderingMethod = OrderingMethod.Automatic; // Settings
navigation.SaveChanges();
the The Structural Navigation:Sorting to be Automatic,( Sort automatically)
I have my code in an button so when pressing the button i want to set it to be automatic
I have also create a class by the name ClientPortalNavigation.cs My cs file looks like this,
public class ClientPortalNavigation
{
public ClientPortalNavigation(Web web)
{
_web = web;
}
#region CRUD operations
private void EnsureLoaded()
{
if (!_web.IsObjectPropertyInstantiated("AllProperties"))
{
Context.Load(_web, w => w.AllProperties);
Context.ExecuteQuery();
}
}
public void SaveChanges()
{
_web.Update();
Context.ExecuteQuery();
}
public bool GlobalIncludePages { get { return (GlobalIncludeTypes & NodeTypes.Page) == NodeTypes.Page; } set { GlobalIncludeTypes = !value ? GlobalIncludeTypes & ~NodeTypes.Page : GlobalIncludeTypes | NodeTypes.Page; } }
/// <summary>
/// Controls whether publishing pages in this site will be automatically included in current navigation.
/// </summary>
public bool CurrentIncludePages
{
get
{
return (CurrentIncludeTypes & NodeTypes.Page) == NodeTypes.Page;
}
set
{
CurrentIncludeTypes = !value ? CurrentIncludeTypes & ~NodeTypes.Page : CurrentIncludeTypes | NodeTypes.Page;
}
}
/// /// Options that specify how navigation items are ordered. /// public enum OrderingMethod { Automatic, ManualWithAutomaticPageSorting, Manual, } /// /// Controls the ordering of navigation items owned by this site. /// public OrderingMethod OrderingMethod { get { return (OrderingMethod)GetProperty("__NavigationOrderingMethod", 2); } set { SetProperty("__NavigationOrderingMethod", (int)value); } } }

0 commentaires:
Enregistrer un commentaire