Friday, December 21, 2007

SharePoint: How to make navigation headings inherit to subsites

I've seen several messages on newsgroups and the web about this problem. You set up "current navigation" on some site, and you want all of the subsites to have the exact same navigation. The problem is, if you include "headers" in your top-level navigation, they (as well as the links underneath them) do not appear in the navigation of subsites, no matter how much you play with the navigation in the subsites. I'm not sure if this is a bug or if it's by design. I haven't tested the following solution in multiple situations but it might work for you.

1. Add this assembly reference to the master page of the level where you want to supply the authoritative navigation:

<%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

2. Add the following PortalSiteMapDataSource definition to the same master page:


<PublishingNavigation:PortalSiteMapDataSource
ID="SiteMapDSWithHeadings"
Runat="server"
SiteMapProvider="CurrentNavSiteMapProvider"
EnableViewState="true"
StartFromCurrentNode="true"
StartingNodeOffset="0"
ShowStartingNode="false"
TrimNonCurrentTypes="None"
EnableInheritance="True"
/>



3. Find the line that says

<SharePoint:AspMenu id="QuickLaunchMenu" DataSourceId="QuickLaunchSiteMap" runat="server" Orientation="Vertical" StaticDisplayLevels="2" ItemWrap="true" MaximumDynamicDisplayLevels="0" StaticSubMenuIndent="0" SkipLinkText="">

(i.e. the line that begins the definition for your quick launch control).

Change the DataSourceID from "QuickLaunchSiteMap" to "SiteMapDSWithHeadings".

4. Make sure your subsites inherit their master page from parent.

5. In your subsites, under Site Settings->Modify Navigation, set Current Navigation to "Display the same navigation items as the parent site."

Your subsites should now inherit all of the links and headings from the Current Navigation of their parent.

Wednesday, December 12, 2007

InfoPath: How to exit from a browser form and suppress the "save changes" dialog

If you create a browser-based InfoPath 2007 form and use a programmatic submission procedure instead of the built-in submit button, the user may get a "save changes?" prompt when clicking the Close button on the form's toolbar. There are several ways you could avoid this in InfoPath 2003. One would be to set the form's dirty bit to false using the setDirty() method. Another is to programmatically close the form with your own button. I have not seen code to do either of these things in 2007 with managed C# code. Here is my workaround:

Create a button on the form. Add a rule to the button that closes the form on click. Unhide the button when the user clicks your custom submit button.

Tuesday, December 4, 2007

InfoPath: How to programmatically switch the view

The view can be programmatically changed in C# managed code like this:

this.ViewInfos.SwitchView("
name of view");

InfoPath: How to display images in browser-based forms

Use the following method to add an image to a browser-based form in InfoPath 2007 using C# managed code:

Your image must be available somewhere by URL.
1. Add a rich text control to the form.
2. Add the following code to the form:

XPathNavigator ng = MainDataSource.CreateNavigator().SelectSingleNode("XPath to the binding of the rich text control", NamespaceManager);
ng.AppendChild("<img xmlns=\"http://www.w3.org/1999/xhtml\" src=\"URL of your image\" />");

This modifies the XML node of the rich text box, adding an XHTML image as a child.