Set Navigation Settings
A while back I had created a command which allowed you to set the navigation elements/nodes for a given site. The command allowed you to also set a couple of basic switches that appear on the Site Navigation Settings page (Home > Site Settings > Modify Navigation) but it didn't allow you to set all the flags. I thought about possibly modifying this command to allow all the flags to be set but then decided it would introduce some complexities that were just not worth introducing.
In the end I decided to create a new command, gl-setnavigationsettings, which would allow you to set all the values found on the above mentioned page with the exception of the navigation nodes themselves. Fortunately, the code for this was extremely simple (especially considering I already had chunks that I could use thanks to the other command I had created). The code simply sets properties on the PublishingWeb object based on parameters provided by the user:
1: public override int Run(string command, System.Collections.Specialized.StringDictionary keyValues, out string output)
2: {
3: output = string.Empty;
4:
5: InitParameters(keyValues);
6:
7: string url = Params["url"].Value.TrimEnd('/');
8:
9: using (SPSite site = new SPSite(url))
10: {
11: using (SPWeb web = site.AllWebs[Utilities.GetServerRelUrlFromFullUrl(url)])
12: {
13: PublishingWeb pubweb = PublishingWeb.GetPublishingWeb(web);
14:
15: if (Params["showsubsites"].UserTypedIn)
16: pubweb.IncludeSubSitesInNavigation = bool.Parse(Params["showsubsites"].Value);
17:
18: if (Params["showpages"].UserTypedIn)
19: pubweb.IncludePagesInNavigation = bool.Parse(Params["showpages"].Value);
20:
21: OrderingMethod sortMethod = pubweb.NavigationOrderingMethod;
22: if (Params["sortmethod"].UserTypedIn)
23: {
24: sortMethod = (OrderingMethod)Enum.Parse(typeof (OrderingMethod), Params["sortmethod"].Value, true);
25: pubweb.NavigationOrderingMethod = sortMethod;
26: }
27:
28: if (sortMethod != OrderingMethod.Manual)
29: {
30: if (Params["autosortmethod"].UserTypedIn)
31: pubweb.NavigationAutomaticSortingMethod = (AutomaticSortingMethod)Enum.Parse(typeof(AutomaticSortingMethod), Params["autosortmethod"].Value, true);
32: if (Params["sortascending"].UserTypedIn)
33: pubweb.NavigationSortAscending = bool.Parse(Params["sortascending"].Value);
34: }
35: else
36: {
37: if (Params["autosortmethod"].UserTypedIn)
38: Console.WriteLine("WARNING: parameter autosortmethod is incompatible with sortmethod {0}. The parameter will be ignored.", sortMethod);
39: if (Params["sortascending"].UserTypedIn)
40: Console.WriteLine("WARNING: parameter sortascending is incompatible with sortmethod {0}. The parameter will be ignored.", sortMethod);
41: }
42:
43: if (Params["inheritglobalnav"].UserTypedIn)
44: pubweb.InheritGlobalNavigation = bool.Parse(Params["inheritglobalnav"].Value);
45:
46: if (Params["currentnav"].UserTypedIn)
47: {
48: CurrentNavSettingsEnum currentNav = (CurrentNavSettingsEnum)Enum.Parse(typeof (CurrentNavSettingsEnum), Params["currentnav"].Value, true);
49: if (currentNav == CurrentNavSettingsEnum.InheritParent)
50: {
51: pubweb.InheritCurrentNavigation = true;
52: pubweb.NavigationShowSiblings = false;
53: }
54: else if (currentNav == CurrentNavSettingsEnum.CurrentSiteAndSiblings)
55: {
56: pubweb.InheritCurrentNavigation = true;
57: pubweb.NavigationShowSiblings = true;
58: }
59: else if (currentNav == CurrentNavSettingsEnum.CurrentSiteOnly)
60: {
61: pubweb.InheritCurrentNavigation = false;
62: pubweb.NavigationShowSiblings = false;
63: }
64: }
65:
66: pubweb.Update();
67: }
68: }
69:
70: return 1;
71: }
72:
73: internal enum CurrentNavSettingsEnum
74: {
75: InheritParent,
76: CurrentSiteAndSiblings,
77: CurrentSiteOnly
78: }
The syntax of the command can be seen below:
C:\>stsadm -help gl-setnavigationsettings
stsadm -o gl-setnavigationsettings
Sets the navigation settings for a web site (use gl-setnavigationnodes to change the actual nodes that appear).
Parameters:
-url <site collection url>
[-showsubsites <true | false>]
[-showpages <true | false>]
[-sortmethod <automatic | manualwithautomaticpagesorting | manual>]
[-autosortmethod <title | createddate | lastmodifieddate>]
[-sortascending <true | false>]
[-inheritglobalnav <true | false>]
[-currentnav <inheritparent | currentsiteandsiblings | currentsiteonly>]
Here's an example of how to set various settings on a given web:
stsadm -o gl-setnavigationsettings -url "http://intranet/sitedirectory" -showsubsites true -showpages true -sortmethod automatic -autosortmethod title -sortascending true -inheritglobalnav false -currentnav currentsiteandsiblings
Check out the books I've contributed to at Amazon.com:
Categories
- Article
- General
- PowerShell Cmdlets
- PowerShell Scripting
- Speaking
- STSADM Commands
- Uncategorized
- Scripts
March 14th, 2008 - 08:41
Hi, would you be willing to send me the dll you came up with for setting the navigation to inherit from the parent site?
March 14th, 2008 - 09:53
There’s links under the Helpful Resources section in the top right to download the code and a WSP for all these commands.
November 1st, 2008 - 07:47
Hi,
Thanks for the great extension. Just one small question, do you perhaps have a command / switch that would enable me to execute this on an entire site collection?
Thanks in advance,
Francois Pienaar
November 1st, 2008 - 19:12
Not at the moment but I am working on something to do it.
December 10th, 2008 - 01:32
Hi All,
I am trying to delete all list items from a calendar in WSS. i wrote the command
D:\Documents and Settings\asharma>stsadm -0 gl-deletelistitem -url “http://amreesh:200/Lists/EventCalendar/calendar.aspx”
i am getting error: missing operation name or operation is invalid.
your ideas are welcome..
Regards
Amreesh
December 10th, 2008 - 08:42
Amreesh – it’s “stsadm -o”, not “stsadm -0″
December 10th, 2008 - 08:45
i tried with -o also but didnt work. i didnt add the .wsp(solution file) to the solutions. is this the real problem.????
December 10th, 2008 - 08:49
Well of course you have to deploy the commands first
stsadm -o addsolution -filename “c:\Lapointe.SharePoint.STSADM.Commands.wsp”
stsadm -o deploysolution -local -allowgacdeployment -name “Lapointe.SharePoint.STSADM.Commands.wsp”
stsadm -o execadmsvcjobs
December 10th, 2008 - 09:07
Thanks Gary……
regards
Amreesh
December 11th, 2008 - 06:16
Hi Gary,
I deployed Lapointe.SharePoint.STSADM.Commands.wsp on my sharePoint site. I could add solution and deploy it successfully on MOSS now i am running the following command to delete the list items of a Calandar list:
D:\Documents and Settings\asharma>stsadm -o gl-deletelistitem -url “http://shserver:401/LAPP2.0/Lists/Absences/Leave%20Planner.aspx”
But I am not able to.
Please give some hints if ia m making mistake anywhere…
Thanks
Amreesh
December 11th, 2008 - 08:40
Are you getting any kind of error?
December 11th, 2008 - 08:43
NO it doesnt give any error but directlty goes to all the stsadm custom commands by You. On WSS it is working fine but when i try on a remote machine whcih is having MOSS, i am not able to….Any Specific reason???
December 14th, 2008 - 10:08
Is this remote machine part of the farm? You can’t use stsadm remotely.
December 15th, 2008 - 00:26
Hi Gary,
It worked later on. I was accessing system remotely but i was writing the commands on the same farm. Actually i was not having proper permissions in the system. Later on it worked….
Thanks
Amreesh
March 24th, 2009 - 15:51
As everyone else says… Thanks for these great additions. I am trying to work a way to create over 70 subsites via a script. After numerous tries, I am using the createweb option generated from a previous template. The Top Links do not carry over though. I was hoping to use the gl-setnavsettings you created. It only lists treeview and quicklaunch as options though. Am I missing something?
thanks,
March 24th, 2009 - 15:59
For the WSS version I only support those two options. You need the MOSS version for the other options.
November 11th, 2010 - 21:30
Hi Gary,
I am using SharePoint 2007 on Win Server 2008.
I dont have gl-setnavigationsettings opeeration with stsadm.
Can you please help me to make it available as I am trying to execute the operation for few of the sites.
Thanks in Advance. BTW, it was a nice post.
Regards,
Kaushal
November 12th, 2010 - 09:15
Go to the download page – download the WSP for your environment – follow the instructions for installing.