Software Development Technologies and Solutions
SharePoint | .NET | MCMS | MS SQL | Office


Hi all, I've received the following message from MOSS 2007 interested guy, he did use the idea of my previuos post:  Customizing SharePoint 2007 Navigation Menu.

 

Hi, we needed the diferent color tabs, and we use your idea but with some modification. Hope it works for some people:

<SharePoint:AspMenu
  ID="TopNavigationMenu"
  Runat="server"
  DataSourceID="topSiteMap"
  EnableViewState="false"
  AccessKey="<%$Resources:wss,navigation_accesskey%>"
  Orientation="Horizontal"
  StaticDisplayLevels="2"
  MaximumDynamicDisplayLevels="1"
  DynamicHorizontalOffset="0"
  StaticPopoutImageUrl="/_layouts/images/menudark.gif"
  StaticPopoutImageTextFormatString=""
  DynamicHoverStyle-BackColor="#CBE3F0"
  SkipLinkText=""
  StaticSubMenuIndent="0"
  CssClass="ms-topNavContainer">
  <StaticMenuItemStyle CssClass="" ItemSpacing="4px" />
  <StaticSelectedStyle CssClass="ms-topnavselected" ItemSpacing="4px" />
  <StaticHoverStyle CssClass="ms-topNavHover"/>
 <StaticItemTemplate>
  <div class="<%# GetMenuItemClass(Eval("Text").ToString())%>" style="height:100%">
   <a href="<%# Eval("DataPath") %>">
    <%# Eval("Text") %></a></div>
 </StaticItemTemplate>
 <DynamicMenuStyle  BackColor="#F2F3F4" BorderColor="#A7B4CE" BorderWidth="1px"/>
 <DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
 <DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
 <DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
</SharePoint:AspMenu>
<script runat="server" type="text/C#">
 private string GetMenuItemClass(string nombreP)
 {
  string cssClass, lists, name, style, temp;
  cssClass = System.Configuration.ConfigurationSettings.AppSettings["cssDefault"].ToString();
  list = System.Configuration.ConfigurationSettings.AppSettings["ListSHP"].ToString();
  SPWeb web = SPContext.Current.Site.RootWeb ;
  //SPWeb web = SPContext.Current.Web;
  SPListItemCollection items = web.Lists[list].Items;
 
  foreach (SPListItem item in items)
  {
   name = System.Configuration.ConfigurationSettings.AppSettings ["TabName"].ToString();
   style = System.Configuration.ConfigurationSettings.AppSettings["TabStyle"].ToString();
   if (item[nombre].ToString().ToUpper() == TabName.ToUpper())
   {
    cssClass = item[style].ToString();
    break;
   }
  }
 
  return cssClass;
 }
</script>


The idea is to use a SharePoint List to manage the styles of the tabs.

So, we have a SharePoint List with two fields one with the name of the tab and other with the colour wanted for each tab. you have to create the style that you want to apply to each tab.

we have themes for each site, so in each theme.css we add the default styles for each tab in our case:
 

.green{
 border-color: #428914;
 border-style: solid;
 border-width: 1px 1px 0px 1px;
 background-image: url("topnav_green.gif");
 background-repeat:repeat-x;
 background-color: #F0F8E7;
 color: #428914;
 font-size: 11pt;
 font-family: Arial;
 vertical-align:middle;
}
.green a{
 color:#FFFFFF;
}
.blue{
 border-color: #0073BA;
 border-style:solid;
 border-width: 1px 1px 0px 1px;
 background-image: url("topnav_azul.gif");
 background-repeat:repeat-x;
 background-color: #E3EAF5;
 color: #0073BA;
 font-size: 11pt;
 font-family: Arial;
 vertical-align:middle;
}
.blue a{
 color:#0073BA;
}
 
 
and the hover and selected depends of the theme that you have on the site that you're viewing
 
thanks Mahdi!

SQL Server 2008, the next release of Microsoft SQL Server, provides a comprehensive data platform that is more secure, reliable, manageable and scalable for your mission critical applications, while enabling developers to create new applications that can store and consume any type of data on any device, and enabling all your users to make informed decisions with relevant insights. Download release & Read more

A new CodePlex projects for community WCM code samples announced by Spencer Harbar & Andrew Connell:

 

SharePoint 2007 WCM Field Controls
A collection of sample Field Controls for use within Publishing Sites built using Office SharePoint Server 2007's Web Content Management features.

 

SharePoint 2007 WCM Web Parts
A collection of sample Web Parts for use within Publishing Sites built using Office SharePoint Server 2007's Web Content Management features.

 

SharePoint 2007 WCM Utilities
A collection of useful utilities for Publishing Sites built using Office SharePoint Server 2007's Web Content Management features.

 

Hi everyone, I've seen that many people are using HTML content web part for displaying Flash animation, I don't recommend this approach for many reasons, one of them being you won't tell your client to edit HTML code for changing Flash properties; so it is better to have a dedicated web part for rendering Flash animation, I've developed a simple one, here is the code:

flash Web Part

using System;
using System.Runtime.InteropServices;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Text;

using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace FlashWP
{
    [Guid("859a6d18-dcc2-430f-9873-f414d49839a4")]
    public class FlashWP : System.Web.UI.WebControls.WebParts.WebPart
    {
        public FlashWP()
        {
           
        }
        private int flashWidth = 300;
        private int flashHeight = 200;
        private string flashUrl;

        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Width"),
        WebDescription("Width of the flash")]
        public int FlashWidth
        {
            get { return flashWidth; }
            set { flashWidth = value; }
        }


        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("Height"),
        WebDescription("Height of the flash")]
        public int FlashHeight
        {
            get { return flashHeight; }
            set { flashHeight = value; }
        }


        [Personalizable(PersonalizationScope.Shared),
        WebBrowsable(true),
        WebDisplayName("URL"),
        WebDescription("Url of the flash file")]
        public string FlashUrl
        {
            get { return flashUrl; }
            set { flashUrl = value; }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!String.IsNullOrEmpty(FlashUrl))
            {
                StringBuilder _outstring = new StringBuilder();

                _outstring.Append("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" ");
                 _outstring.Append("codebase=\"

http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" ");
                 _outstring.Append("WIDTH=");
                 _outstring.Append(flashWidth.ToString() );
                 _outstring.Append(" HEIGHT=" );
                 _outstring.Append(flashHeight.ToString());
                 _outstring.Append("> " );
                 _outstring.Append("<PARAM NAME=movie VALUE=\"");
                 _outstring.Append(flashUrl );
                 _outstring.Append("\"> " );
                 _outstring.Append("<PARAM NAME=WMODE VALUE=\"Transparent\">");
                 _outstring.Append("<PARAM NAME=quality VALUE=high> " );
                 _outstring.Append("<EMBED src=\"" );
                 _outstring.Append(flashUrl );
                 _outstring.Append("\" quality=high wmode=\"transparent\" WIDTH=\"");
                 _outstring.Append(flashWidth.ToString() );
                 _outstring.Append("\" HEIGHT=\"" );
                 _outstring.Append(flashHeight.ToString() );
                 _outstring.Append("\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"

http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED> ");
                 _outstring.Append("</OBJECT>");
                writer.Write(_outstring.ToString());
            }
            else
            {
                writer.Write("Modify Webpart to add content URL");
            }
        }
    }
}

 

To apply this code, you will need SharePoint Services 3.0 extenstions for Visual studio  2005 to be installed. 

Download source here

If you are a SharePoint developer, then you will be in need to customize the default SharePoint menu control.  This new feature in MOSS 2007 is great and it allows for suitable level of customization, but unfortunately, this level is not enough for such portal which I’m involved in these days.

I’ve decided to customize the default menu instead of developing new control. To realize the problem suppose that you want your menu to have the following structure:

Site1   Site2  Site3  Site4 …..

   Site1Child1 . Site1Child2 . Site1Child3…

As you see, every static item has its own style, also it should has its own hover style, and dynamic items should appear horizontally in case of mouse over the static item.
If you edited your master page by sharepoint designer, you will notice that the default SharePoint menu allows you to define only one class for all static items, so we need to edit the static menu template, but even though, the template allows you only for editing "link"s' inner HTML, however you can add another link inside this template, it is a good idea for applying deferent classes:

 

<StaticItemTemplate>
    <div id=
"Static" runat="Server" class='<%# GetStaticClass()%>' onmouseover='<%# GetShowFunction()%>' onmouseout='<%# GetHideFunction()%>'>
        <asp:hyperLink runat=
"Server" id="urlNavS"  NavigateUrl='<%# Eval("DataPath")%>' Text='<%# Eval("Text")%>' />
    </div>
    <div id='<%# GetDynamicID()%>' class='dynPanel'  onmouseover='<%# GetShowFunction()%>' onmouseout='<%# GetHideFunction()%>'></div>
 </StaticItemTemplate>

 

You will notice that I’ve put all classes and javascript functions to be driven from C# script, but first you should be permitted from SharePoint to execute C# script in SharePoint pages. To do that you need first to add the following section under <SafeMode> tag in web.config:

 

<PageParserPaths>
   <PageParserPath VirtualPath=
"/_catalogs/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>

 

I’ve written C# script for providing class name for each item and JavaScript functions.
That will solve the first problem, but further more we need to display dynamic items horizontally, I think this hard to be done by the default dynamic template, so I’ve assigned a class to hide the default dynamic items and I’ve began to generate them by C# code using OnDataBound event.
Here is the full code:


<div id="MenuDiv">
     <SharePoint:AspMenu ID=
"GlobalNav" Runat="server" DataSourceID="SiteMapDataSource1" Orientation="Horizontal" StaticDisplayLevels="1" MaximumDynamicDisplayLevels="1" StaticSubMenuIndent="2" DynamicHorizontalOffset="0" DynamicVerticalOffset="4" StaticEnableDefaultPopOutImage="false" ItemWrap="false" Width="0%" OnDataBound="MenuDataBound">
                 
          <StaticMenuItemStyle CssClass=
"" ItemSpacing="4px" />
          <StaticSelectedStyle CssClass=
"" ItemSpacing="4px" />
          <DynamicMenuItemStyle CssClass=
"dynamicItems" />
             <StaticItemTemplate>
                  <div id=
"Static" runat="Server" class='<%# GetStaticClass()%>' onmouseover='<%# GetShowFunction()%>' onmouseout='<%# GetHideFunction()%>'>
                       <asp:hyperLink runat=
"Server" id="urlNavS"  NavigateUrl='<%# Eval("DataPath")%>' Text='<%# Eval("Text")%>' />
                  </div>
                  <div id='<%# GetDynamicID()%>' class='dynPanel'  onmouseover='<%# GetShowFunction()%>' onmouseout='<%# GetHideFunction()%>'></div>
              </StaticItemTemplate>
             <StaticHoverStyle CssClass=
"topNavHover"/>
            </SharePoint:AspMenu>
            <PublishingNavigation:PortalSiteMapDataSource ID=
"siteMapDataSource1" Runat="server" SiteMapProvider="CombinedNavSiteMapProvider" EnableViewState="true" StartFromCurrentNode="true" StartingNodeOffset="0" ShowStartingNode="false" TreatStartingNodeAsCurrent="true" TrimNonCurrentTypes="Heading"/>
            <div id=
"dynamicItems" runat="server"></div>


           
<script runat="server">
            int stCount
= 0;
           
            protected string GetStaticClass
()
            {
                  stCount
+= 1;
                  return "staticItem"
+ stCount .ToString() ;                            
            }
           
            protected string GetDynamicID
()
            {
                  return "DynamicItem"
+ stCount .ToString() ;                           
            }
       
           
            protected string GetShowFunction
()
            {
                  return "showDynamicItems("
+ stCount .ToString() + ")" ;                           
            }
           
            protected string GetHideFunction
()
            {
                  return "hideDynamicItems("
+ stCount .ToString() + ")" ;                           
            }
       
            protected void MenuDataBound
(object sender, EventArgs e)
            {
                  int ItemIndex
= 0;
                  int subIndex
= 0;
                  string divContent
= "";
                 
                  foreach
(System.Web.UI.WebControls.MenuItem item in GlobalNav.Items)
                  {
                        subIndex
= 0;
                        foreach
(System.Web.UI.WebControls.MenuItem cItem in item.ChildItems )
                        {
                              if
(subIndex == 0)
                              {
                                    divContent
+= "<div style='display:none' id='subItems" + ItemIndex.ToString() + "'><table class='MenuSubDiv" + (ItemIndex + 1).ToString() + "' ><tr>";
                              }
                              divContent
+= "<td><a href='" + cItem.DataPath + "'>" + cItem.Text + "</a></td>";
                              if
(subIndex == item.ChildItems.Count-1)
                              {
                                    divContent
+= "</tr></table></div>";
                              }
                              else
                              {
                                    divContent
+= "<td>&nbsp;<img src='/_layouts/images/menu_sub_bullet.gif'/>&nbsp;</td>";
                              }
                              subIndex
+= 1;
                        }
                        ItemIndex
+= 1;
                  }
                  dynamicItems
.InnerHtml += divContent ;                                 
            }
           
       
</script>
       
<script language="javascript" type="text/javascript">
       
            function showDynamicItems
(num)
            {
                  try
                  {
                        var dv
= document.getElementById("subItems" + (num -1).toString());
                        var dynCont
= document.getElementById("DynamicItem" + num.toString());
                                   
                        if
(dynCont.style.display!="block")
                        {
                              hideAll
();
                              dynCont
.innerHTML = dv.innerHTML ;
                              dynCont
.style.display = "block" ;
                        }
                  }
                  catch
(e)
                  {
                  }
            }
           
            function hideAll
()
            {
                  var count
=1;
                  while
(true)
                  {
                        try
                        {
                              var dynCont
= document.getElementById("DynamicItem" + count.toString());
                              if
(dynCont.style.display != "none")
                              {
                                    dynCont
.style.display = "none" ;
                              }
                              count
+= 1;
                        }
                        catch
(e)
                        {
                              return;
                        }
                  }
            }
           
            function hideDynamicItems
(num)
            {
                  try
                  {
                        var dynCont
= document.getElementById("DynamicItem" + num.toString());
                        dynCont
.style.display = "none" ;
                  }
                  catch
(e)
                  {
                  }
            }
       
       
</script>
   </div>
  

 
[Update April, 11, 2009]
I'm so sorry for being so busy last year, I'm including the CSS file here for all people whom requested it.