Posted by: ericschrader | July 20, 2010

SharePoint static 2nd level current navigation in MOSS 2007

Summary

Requirements:

  • SharePoint MOSS 2007
  • Must be using a Publishing Site

This post will create the SharePoint Current Navigation control that only shows the 2nd level site when browsing, and supports highlighting. The datasource comes from SharePoint as well, so everything is security trimmed, and editable in the browser.

This post is for users who are using SharePoint MOSS 2007 navigation on their website. If you want your current navigation to display the sites and pages under a subsite, but always keep the second level subsite on top, then this post is for you. It’s hard to explain, so reference the screenshot below:

Figure 1 – Our Firm is a subsite under the root of the website. Even if I navigate to Board of Directors above, Our Firm remains at the top of the Current Navigation.

Sitemap data for my screenshot above:

  • Company
    • Our Firm
      • Leadership
        • Management Team
        • Board of Directors
      • Contact Us
      • Locations
    • Investment Banking
    • Sales & Training
    • Research

Sitemap levels:

  • Top Level (root)
    • Second Level site
      • Third Level Site
        • Fourth Level site
        • Fourth Level site
      • Third Level Site
      • Third Level Site
    • Second Level site
    • Second Level site
    • Second Level site

The key is that I want only each second level navigation block to appear when a user is anywhere on or under that second level site. So in my screenshot, you see Our Firm, even if you navigate to Board of Directors.

This navigation also supports highlighting and pages.

Preparing the subsite (our Firm)

  • Check Show Subsites and Show Pages
  • Under Current Navigation, select Display current, below, and siblings. (the middle radio button)

 

Now you need to adjust your current navigation code in the MASTERPAGE to only show the site you are under.

Adjusting the masterpage Current Navigation

Find your PlaceHolderLeftNavBar and replace the contents with this, or you can just mimic it. Take note of the highlighted parts. These are important for this post.

Placeholders are content buckets in your masterpages, the content inside them is what is important. Just make sure you don’t have multiple of the same ID’s on the same masterpage.

 

Here is the code:

<asp:ContentPlaceHolder id=”PlaceHolderLeftNavBar” runat=”server”>

    <!– Current Navigation –>

    <!– Current Navigation –>

    

    <SharePoint:AspMenu ID=”CurrentNav” runat=”server” datasourceID=”SiteMapDS” orientation=”Vertical”

    StaticDisplayLevels=”4″ MaximumDynamicDisplayLevels=”1″ StaticSubMenuIndent=”1″ ItemWrap=”true”

    AccessKey=”3″ CssClass=”leftNav” SkipLinkText=”<%$Resources:cms,masterpages_skiplinktext%>”>

        <StaticHoverStyle CssClass=”LeftStaticHover” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

        <StaticSelectedStyle CssClass=”LeftStaticSelected” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

        <DynamicMenuStyle CssClass=”LeftDynamicMenu” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

        <DynamicMenuItemStyle CssClass=”LeftDynamicMenuItem” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

            <LevelMenuItemStyles>

                <asp:menuitemstyle CssClass=”parent” Font-Underline=”False” />

                <asp:menuitemstyle CssClass=”child” Font-Underline=”False” />

                <asp:menuitemstyle CssClass=”leftNav3″ Font-Underline=”False” />

                <asp:menuitemstyle CssClass=”leftNav4″ Font-Underline=”False” />

                <asp:menuitemstyle CssClass=”leftNav5″ Font-Underline=”False” />

            </LevelMenuItemStyles>

        <StaticMenuStyle CssClass=”LeftStaticMenu” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

        <DynamicSelectedStyle CssClass=”LeftDynamicSelected” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

        <StaticMenuItemStyle CssClass=”LeftStaticMenuItem” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False” />

        <DynamicHoverStyle CssClass=”LeftDynamicHover” Font-Bold=”False” Font-Italic=”False” Font-Overline=”False” Font-Strikeout=”False” Font-Underline=”False”/>

    </SharePoint:AspMenu>

    <PublishingNavigation:PortalSiteMapDataSource ID=”SiteMapDS” Runat=”server”

    SiteMapProvider=”CombinedNavSiteMapProvider

    StartFromCurrentNode=”True”

    StartingNodeOffset=”1″ TrimNonCurrentTypes=”Page”/>

</asp:ContentPlaceHolder>

 

Here is an explanation of the above code:

SharePoint:AspMenu

Creates an ASP.Net menu (html) using tables

datasourceID

This sets the Datasource to populate the HTML. In this case, it points to the ID of the PublishingNavigation:PortalSiteMapDataSource.

StaticDisplayLevels

How many levels to display (non flyouts) starting from the data returned. If your datasource only returns second level sites, the ASP Menu sees these as the first level.

MaximumDynamicDisplayLevels

1 disables flyouts. 2 would have the 5th level links as a flyout.

 

Datasource properties

PublishingNavigation:PortalSiteMapDataSource

Creates a datasource on our page. This control uses the SharePoint Navigation.

ID

Sets the ID of this datasource for ASP.Menu or other controls to access the data

SiteMapProvider

There are a lot. I really like CombinedNavSiteMapProvider for this blog post. It was the best I found. Here are a few more

StartFromCurrnetNode

Not sure why, but I think this controls the highlighting of sub sites. If this is set to false, I think the returned data source does not know what site you are located in. More here

StartingNodeOffset

This is the reason why we see the second level page at the top of our left navigation, and not the root. We trim the root, as 0 is default, but we specify 1. This trims one level off our data source. See a full explanation here

TrimNonCurrnetTypes

Since we specify pages, this removes all pages from the datasource that are not under the current site, and not below. See here for more info

 

See this same table (and ALL OTHER PROPERTIES!) here: http://msdn.microsoft.com/en-us/library/bb897657.aspx

 

Basically, just play around with the code. You can learn a lot just modifying the above properties. I basically wanted this blog post to show a neat configuration of SharePoint navigation :)

Good luck!

Posted by: ericschrader | June 10, 2010

HTML Hyperlink tags and word-wrap padding fix

Recently, I noticed when I have the following code, my text wraps and ignores my padding for the second line.

<style>

.menuItemLvl2 {

Padding-left: 24px;

}

</style>

<div><a class=menuItemLvl2 href=#>Restructuring & Recapitalization</a></div>

I wanted the hyperlink a tag to wrap and respect the padding. I also had highlighting on the A hyperlink tag for :hover state, so I coudnt use Margin-left:24px.

I applied the following CSS to fix my issue: ( I only add the green highlighted text to the above code)

<style>

.menuItemLvl2 {

Padding-left: 24px;

Float:left;

Width:200px; /* Note: you cannot use 100%, as the padding pushes the element out of its container that has a width of 224px. Use container width minus padding of this element*/

}

</style>

<div><a class=menuItemLvl2 href=#>Restructuring & Recapitalization</a></div>

And on hover: (note, I did not include the code for a:hover in this example, but just set the background-color: #666666 or whatever color)

Works in Firefox and IE7.

Posted by: ericschrader | February 26, 2010

SharePoint 2007 Branding links

  • Real World Branding with SharePoint Server 2007 Publishing Sites

    http://msdn.microsoft.com/en-us/library/ee354191.aspx

  • Heather’s Base Master Page Files
    Base master page files with necessary content placeholders to run a SharePoint site. All branding and added code is stripped out.
  • CSS Reference Chart
    Informative chart of popular CSS classes and IDs.
  • Design Gotcha List
    List of items to watch out for when you are rebranding SharePoint. Includes red flags for problem areas and screenshots.
  • SharePoint Resources
    Blog posts, articles, tools, product information and more. Large resource list focused on customization, but also with many non-customization related resources
  • URL Quick List
    List of links to commonly used administrative functions.
  • SharePoint Tools for Style: How to Start Branding SharePoint

    You have a site design and your trusty copy of SharePoint Designer, but now what? In this session, we cover SharePoint branding concepts and benefits and show step by step how to create a custom master page using Microsoft Office SharePoint Designer.

    Slide Deck Great slides on branding

     

     

My last post offered clues as to why Data View web parts break. All my previous web parts were using custom Layouts to strip out all the surrounding layout tables.

Here is a rough idea how the default Layout is constructed.

Figure 1- The above is a default Multi-item XSLT Data View web part template without paging (Display all items). Notice how there is a Table Row (TR) for each data row.

Normally, in the past, I did not want my data to be separated in its own table row (TR). I wanted my data to be separated with a line break, or all on the same line, or all in the same row. I would change the layout.

The problem with this is, after multiple re-saving of the ASPX page in SharePoint Designer, the page begins to auto insert generated code into the page or DataView web part. This causes the web part to break and you can lose your template.

The workaround:

Instead of changing your layout, try to work with the existing layout. That’s it!

Here is a diagram of what I wanted:

Figure 2- Basically, it’s the same template as above. I removed the TH text, but left the code. For the Green TD above, I used XSL:Text disable-output-escaping=yes to construct all my conditions.

The above is just my example, as there is a lot of formatting. Basically I have Id’s, Classes, and Numbers I sort by and place in their own TD’s, TR’s (Every 5 cells), and headers for every certain number. Each class has its own TD. (specific to my data schema)

The point I am trying to prove is that outside of the For-Each is intact. All my modifications were around this for-each, but not to my TH class, or any other template.

I got the following error when developing my web part and having my manager log in to check the page. But the page worked fine for me, and was not checked out, as I was not using Publishing Features.

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator

The Problem

The page would load fine for me in browser. In SharePoint Designer, I would have an older data set in my data view web part. I would break the web part when I did a Refresh Data Source, so I left it as it was. I had enough data to continue building out my template.

 

Once I had my manager review my work on his computer, the page gave him the error Unable to display this Web Part. So, I logged in as myself (To make sure the old template was not cached on my computer) and it worked for my user.

 

The Solution

Follow-up: This is not a solution, but a work around. Upon Re-saving the page in SPD, the error occurred once again. See future post on 10/15/09 about XSLT layouts and why they break your data view web part.

At one point, I did have the page checked out, but it seem to automatically disguard it when I tried to check it back in. Really weird, so I made a copy of the Default.aspx page that contained my web part. I right clicked the copy and said Reset to Site Definition.

I noticed the web part was still on the page. I guess since web parts don’t support versioning, resetting the page only resets the code around web part zones. My web part was still on the copy. I suspected that if I reset the page and that it just might work now. I logged in as another user and it worked.

Here are the steps:

  1. Make a copy of the ASPX page containing your “Broken” web part
  2. Reset the COPY to Site Definition
  3. Try the newly reset page and see if it works for your users.

 

Summary

I have noticed a lot of XSLT web part errors. I am starting to log them in one place as an archive of solutions, rather than abandoning my web part and starting over each time I get an error.

Posted by: ericschrader | October 9, 2009

SharePoint XSLT error – Unable to display this Web Part.

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

This error could be caused by missing double quotes around your HTML markup attributes. For instance, the error below is missing double quotes around the table width=”600″ attribute. Simple change width=600 to width=”600″ and everywhere you have an attribute value (This includes classes, etc.).


Figure 1- Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

If you have seen this error, there might be a very simple solution.

The Solution:

Make sure all HTML template attribute values are contained in double quotes (eg. “value” and not just value.).

In my above example, I modified a Table tag inside my body template of the Data View web part. I replaced <table width=”600″> with <table width=600> and got the above error. This happens with classes and all HTML tag attributes (class=”Testing” is valid for an XSLT template in SharePoint, whereas class=testing causes the Unable to display this Web Part error.

This error is really broad, and I’m sure it won’t help everyone, but it’s a good start and easy fix for some situations.

I found an interesting thing about the error message I was getting with SharePoint Designer. The error is:

“Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as FrontPage. If the problem persists, contact your Web server administrator”

I had a complicated Data view web part that I did not want to recreate.

The Solution:

Open the aspx file in notepad from SharePoint Designer. If you notice a bunch of HTML markup formatted as “&gt;” etc, then open the file normally in SharePoint designer Code View. Copy ALL the code and paste it into Notepad. Copy the code from notepad and replace your code view text. Save and view in browser. No more XSL DATA VIEW ERRORS!

The code view actually contains a rich text type of rendering. When you copy it out and paste it in notepad, it loses all of the special formatting. This allows the page to render correctly.

Posted by: ericschrader | August 27, 2009

Eric Schrader’s SEO Tips

Eric Schrader goes over his best SEO Tips. First, always post your keywords as a page title. This is the number one way to get to the top of search engines.

Second, Make sure your HTML output is complete, and not patched together, or all images. You want the text to be indexed.

Third, Add links next to your sites mission statement, like More about Eric, etc. When people click on these links, your region towards the top of your page becomes indexed. Div layer templates are a good way to get your mission statement to the top of your HTML, and position it on the right or below navigation by floating the layer. I have found that location or having a link indexes the content as a Google description of the site.

Why am I writing this post? Well, I wanted a blog post that had my name. Right now, my name is #16 when I Google “Eric Schrader”. I want to be 1st. Give it a few weeks and after I forget about it, I will probably be in the top 2 or 3 results for Eric Schrader.

Also, keywords that have to do with your blog will help as well. For instance, I will say SharePoint a lot, just to make clear that’s what my blog is about. Notice how this is also in my title.

The Problem

Visual Studio requires a ScriptManager to compile a Ajax enabled solution for a SharePoint web part.

Visual Studio Error on compile says:

Solution.cs: (Build Error)

Error    1    The type or namespace name ‘ScriptManager’ could not be found (are you missing a using directive or an assembly reference?)    C:\…\Solution.cs

 

 

The Solution:

A Reference dll is missing in your solution. You need to add a reference to System.Web.Extentions.

Posted by: ericschrader | August 27, 2009

Page Titles disappear after Ajax event

The Problem:

SharePoint page titles when using Ajax may turn to square icons. This is the rendering of the title tag in the masterpage, or where the page title is specified. A normal SharePoint masterpage specifies the title on 3 lines, the first line is for the opening tag, second line contains the content place holder for page title, and the 3rd line in the masterpage’s title is for the closing title tag. You get something that looks like this:

BlueBand.master
<Title ID=onetidTitle>

        <asp:ContentPlaceHolder id=PlaceHolderPageTitle runat=”server”/>

</Title>

 

Rendered HTML after Ajax panel update:
<title>

    

    Home

 

</title>

 

Basically, the tabs indenting “Home” are rendered as nothing in IE7 Page Title, but in the tab title, they are rendered as 3 little squares.

The Solution:

Put the title tag on one line! That’s it! No need for JavaScript or anything else when using Ajax on a page! Just edit the CORRECT masterpage, (For Publishing Portal, the default is BlueBand.master, for Team and Collaboration sites, it’s Default.master) I made the mistake of editing Default.Master for the fix and was using a Publishing Portal, and didn’t see my changes!

Here’s the code fix:

BlueBand.master (or Default.master):
<title id=”onetidTitle”><asp:ContentPlaceHolder id=”PlaceHolderPageTitle” runat=”server”/></title>

 

Having ANY tabs in your source code will render nothing for your page title. You MAY use spaces, but NOT formatting tabs.

Older Posts »

Categories