0

I am receiving the following error when attempting to add a Link to the Top Navigation Bar.

"Exception calling "AddAsLast" with "1" argument(s): "Access is denied"

Here is the code:

$web = Get-SPWeb $url.Url;

$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList  @($web.Title, $web.Url);  

$web.Navigation.TopNavigationBar.AddAsLast($newLink);
$web.Update();

looking for some reasons and work arounds. Thanks!

1

The syntax is fine, I run the exact same code and it works without a problem.

Some things to look at:

  • Does your account have the right level of access? I know, probably silly question, but just checking
  • What does the ULS log say when you're running this command?
  • Try wrapping in an SPSecurity.RunWithElevatedPrivileges({}) statement
  • Try some more simple cases (get the web then update it immediately without adding anything to the navigation bar to verify navigation is part of the problem)
| improve this answer | |
  • Thanks for checking this for me. The trick for me was to run my powershell window using an account capable of adding top nav links – ChiliYago Jan 11 '11 at 0:31
1

You had .url in the Get-SPWeb variable at the beginning of the script. This works

$web = Get-SPWeb $url

$newLink = New-Object Microsoft.SharePoint.Navigation.SPNavigationNode -ArgumentList  @($web.Title, $web.Url);  

$web.Navigation.TopNavigationBar.AddAsLast($newLink);
$web.Update();
| improve this answer | |
  • If you want to use external URLs, use $TRUE as third parameter. – Smile4ever Apr 19 '17 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.