Repository navigation
PnP.Core - SubSite - Navigation - UseShared #1905
|
Is it possible to set the Web.Navigation.UseShared of sub site using PnP.Core SDK? INavigation.UseShared is readonly: The only way I found was using CSOM (Microsoft.SharePoint.Client.ClientContext.Web.Navigation.UseShared). |
Replies: 1 comment 1 reply
|
Not through the PnP Core model. If you use PnP.Framework, // context must be created for the subsite URL
var xml = @"<Request xmlns=""http://schemas.microsoft.com/sharepoint/clientquery/2009"" SchemaVersion=""15.0.0.0"" LibraryVersion=""16.0.0.0"" ApplicationName=""PnPCore""><Actions><ObjectPath Id=""1"" ObjectPathId=""0"" /><ObjectPath Id=""3"" ObjectPathId=""2"" /><ObjectPath Id=""5"" ObjectPathId=""4"" /><SetProperty Id=""6"" ObjectPathId=""4"" Name=""UseShared""><Parameter Type=""Boolean"">true</Parameter></SetProperty></Actions><ObjectPaths><StaticProperty Id=""0"" TypeId=""{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}"" Name=""Current"" /><Property Id=""2"" ParentId=""0"" Name=""Web"" /><Property Id=""4"" ParentId=""2"" Name=""Navigation"" /></ObjectPaths></Request>";
using var req = new HttpRequestMessage(HttpMethod.Post,
$"{context.Uri.AbsoluteUri.TrimEnd('/')}/_vti_bin/client.svc/ProcessQuery")
{
Content = new StringContent(xml, Encoding.UTF8, "text/xml")
};
await context.AuthenticationProvider.AuthenticateRequestAsync(context.Uri, req);
using var http = new HttpClient();
using var res = await http.SendAsync(req);
var json = await res.Content.ReadAsStringAsync();
// json is the CSOM response array; check [0].ErrorInfo |
Not through the PnP Core model.
INavigationonly implementsIDataModelGet/IDataModelLoad(noIDataModelUpdate) andUseSharedhas no public setter (INavigation.cs). I couldn't find a confirmed REST route either (one report says it's read-only over REST); PnP Framework and CLI for Microsoft 365 both set it via CSOM.If you use PnP.Framework,
PnPCoreSdk.Instance.GetClientContextAsync(context)gives you a CSOMClientContextfrom your PnP Core context. To stay in PnP Core, you can post the CSOM request that CLI for Microsoft 365 sends yourself and let the context's auth provider add the token, which is how PnP Core sends its own CSOM calls.ExecuteRequestAsynccan't carry it because it expects/…