Archive for March, 2006

How to brand a SharePoint Portal or Site for best results – Part 3

Monday, March 27th, 2006

I have been a bit slow in posting on this series. Enjoying my holidays and relaxing most of the time :) Here is another installment of this series.


I will focus on one very important item of SharePoint branding. AlternateHeader.


You can brand pages from different templates, so as to give different look on sites / areas created from different templates. But what about the pages in /_layouts/1033 directory. These are common for all the templates, and as soon as the user hits any of these pages, they would hit the common pages.


Some of the pages in the _layouts directory have code to support the alternate header functionality.


In the page you will find a code block like this:


<%
string alternateHeader = SPControl.GetContextWeb(Context).AlternateHeader;
if (alternateHeader == null || alternateHeader == “”)
{
%>
<TR>


            …… code which is to be used if the alternate header is not defined


            …… goes here.
</TR>
<%
}
else
{
    Server.Execute(alternateHeader);
}
%>


This is a very nice way to brand these pages to have different look and feel when accessed from different template pages. The page to use as the alternate header, is definied in the onet.xml for the template concerned. Be careful and get this right before you create your site with that template, as it cannot be changed by modifying the template once the site is created. So before you start your sharepoint deployment it is essential that you get your alternate headers definited properly in the onet.xml.


Basically, have an alternate header for each template you have. This will let to assign an alternate header to pages from from templates in a 1:1 relationship.


E.g. Say you have several team sites with different branding, HR Site, Finance Site and Sales Site. You have created 3 templates for these 3 site types. Now your goals is to provide a seamless interface to the user whenever the user is presented any page from the _layouts/1033 directory, like viewlsts.aspx which is presented when the user tried to see the documents & lists in any site, or create.aspx when the user is trying to create a list.


Before you create your HR, Finance or Sales site, you will be creating 3 templates which would deifine the different branding of these 3 sites. It is essential that you plan ahead and assign different alternate headers in the onet.xml of these templates. In the &lt;Project&gt; element you can add the attribute AlternateHeader=”/_layouts/1033/HRAlternateHeader.aspx” in case of the HR Template.


Whenever a user opens a page in _layouts/1033 from a site created with the HR Template, he will see a page rendered with the header logic picked up from the HRAlternateHeader.aspx. This is provided the above code to include alternate header functionality is in that page. Not all pages from _layouts/1033 contain that code which is a bit of a pain. So for pages which do not have that code, you might want to edit them and add code support to use alternate headers if defined.


This will give you maximum flexibility while making good use of the excellent functionality provided by the AlternateHeader element. I will discuss creating and modifying templates in a later post.


For some providing more information on this alternate header functionality, see:


Where have I been

Wednesday, March 15th, 2006

I know I have been silent for sometime. I had taken my annual leave and had travelled to my home in India. Am currently sitting at my home and relaxing a bit and enjoying some very well deserved time off.


Won’t be working in SharePoint for a month, and that will get me some good time to mess around with VS2005 and .NET 2.0. So you can guess what I will be blogging about for a month :) I also have to complete some pending post series and will do them in a few days. But will try my best to keep some quality content coming your way.

Ray Ozzie on Clipboard for the Web

Wednesday, March 8th, 2006

We are so used to Ctrl+C and Ctrl+V in working with any application. But we never wondered why we could not do that in web application. We made do with the standard text copy paste features of the browser.


Ray Ozzie showcased a new live clipboard in the O’Reilly eTech conference which is pretty neat and cool. Frank Gruber of Somewhat Frank has some concerns about a need of standard datastructures to support this initiative. I completely agree with him.


Now all we need is a standardised way of implementing this so that it is not just limited to a single application but can be a truly independent web clipboard capable of sharing data between web applications irrespective of the codebase behind the clipboard feature. The worst case would be that we all start taking this concept and implementing it in our applications in innumerable different incompatible ways. It would be great if Microsoft releases a standard set of functions or at least minimum inter-operability requirements within the next few days, before people start coming up with thier own independent ways. We should be able to extend and implement it as we want, but some base features should be decided upon for everyone’s benefit.


Read the original post by Ray. Also there is a simple web based demo which you can try to check out this cool feature.

File Not Found error on SharePoint pages

Monday, March 6th, 2006

This is another very common error I have found people getting completely stumped at. There is no error description, no debug information, nothing. Just a short sweet error saying “File Not Found”.


Don’t get stumped with this error. This is a very straighforward error which actually means that the page did not find one of the files it was asked to process. You must be wondering just what these files can me. So let me try to quickly rememeber on what kind of files I have faced this error.



  1. Any includes, usercontrols added to the template are not accessible. Check the link ( relative or absolute ). Most of the time the link is wrong.

  2. DLL’s missing. If you have added a webcontrol or a webpart in the template, then it might be that the page is unable to find the dll. You may have placed the dll in the bin directory in your website’s root but it might be that that particular page is in some other virtual directory and is referring to some other web.config and bin directory. e.g. For most pages from _layouts, the bin directory it referrs to is _layouts/bin and not _layouts/1033/bin. These kind of errors are very easy to overlook.

  3. If you code for using an alternate header, and the relative path to use that alternate header may be wrong and not loading the page.

I cannot think of any other reasons for this error to generally appear. Let me know if I forgot any. Most of the time it is either #1 or #2 which causes that error.

Websense blocked my site

Wednesday, March 1st, 2006

Recently I was unable to access my blog from work as Websense classified it as Adult content. I was pretty surprised by this and tried to find out what happened, as this will essentially block my site from all my readers who are using Websense.


I submitted my site using their Suggest a URL Category Change link and they replied after 24 hours saying that my request has been processed. According to Websense, as my website in on a shared host ( Yahoo Hosting), one of the sites on that IP had been categorized as Adult Content and so all websites from that IP had been blocked. They also mentioned that the new category will be updated in the next database refresh.


I was not sure when this refresh will happen, and was getting worried if this will happen after a month or so, but thankfully, after 2 days, I was able to access my site from my office, hence indicating that the database refresh had taken place. I did find them a bit late in replying to mails, but overall impressed by their turnover time.


The thing which worries me is that why would Yahoo Hosting host my site on the same IP as an adult content site? Ideally they should have been hosting seperately as they are bound to get other sites blocked or blacklisted. If yahoo is not doing so, then I believe Websense algorithm is in a bit paranoid mode, and classifying all new sites it finds as adult to be safe till someone reviews it. Which is not a good thing to do.


Anyways all’s well that ends well. My site is accessible again so no complaints. But am a bit worried about other web filtering companies which I am not aware of and may be blocking my site from many potentials readers. And there is no way for me to find out till someone mails me or till I access my site from those systems.

Using WebControls in templates instead of WebParts

Wednesday, March 1st, 2006

This is a small tip which I am not sure if many people are aware. When you try to add a WebPart to certain locations in your site definition files, sometimes the page will crash and refuse to load. If you place a webcontrol instead, then it works.


I generally use the starter webpart template and change it to inherit from a WebControl instead. I also create a wrapper webpart, which wraps my webcontrol, hence giving me flexibility to use the webpart or webcontrol interchangebly. You will get access to full SharePoint context even from a WebControl.


The following piece of code depicts the wrapper webpart for MyWebControl.


The WebControl Code:


namespace MyCustomCode
{
 public class MyWebControl : System.Web.UI.WebControls
 {
  // WebControl code goes here
 }
}


The WebPart Code:


namespace MyCustomCode
{
 public class MyWebPart : Microsoft.SharePoint.WebPartPages.WebPart
 {
  private MyWebControl webControl;
  


  protected override void RenderWebPart(HtmlTextWriter output)
  {
   this.webControl.RenderControl(output);
  }


  protected override void CreateChildControls()
  {
  
webControl = new MyWebControl();
   this.Controls.Add(webControl);
  }
 }
}


Edited: Formatted code for line breaks.

How to brand a SharePoint Portal or Site for best results – Part 2

Wednesday, March 1st, 2006

For this entry I will focus on CSS branding. This is the easiest way to brand an out of box SharePoint installation. Every entity in SharePoint ( table, header, page header, title bar, web part header, etc ) there is a class defined.


SharePoint defines these classes in various css files located at C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS\1033\STYLES. I won’t go into a lot of details on what each style corresponds to. A comprehensive list is available from the MSDN article Customizing SharePoint Sites and Portals: Style Sheet Class Reference Tables, Part 3.


One thing to be careful here, is that these files are common per server. So if you are running 2 portals from the same server, any change to these will affect both your portal or wss installations. Also, these changes are site or portal wide as the case may be, and cannot be used to selectively brand a particular site or area.


Themes can be used in such a case, but personally I tend not to use them a lot as they just cause confusion on which is the actual file responsible for the design. But if you business case justifies it, you can very well use themes. They just provide an addition layer of css over the default css styles.


Most of my branding assignments are based on full customization of all the templates. I will discuss this in detail later on. It offers a lot of flexibility but is the most painful to implement.