Browsing Category SharePoint

Using WebControls in templates instead of WebParts

March 1st, 2006 // 5:03 pm @

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.

Category : SharePoint

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

March 1st, 2006 // 3:03 pm @

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.

Category : SharePoint

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

February 23rd, 2006 // 3:16 pm @

Recently I have been involved in many projects on branding and customizing SharePoint. Hence I decided that combining everything I have learnt from it would make a good topic for a series of posts. I find very less tutorials on how to effectively brand SharePoint. By effectively, I mean, giving the maximum amount of flexibility which not necessarily is the easiest thing to do.


Let’s try to see in how many ways can you brand sharepoint.



  1. Style sheet branding. This is a quick and easy way to brand your SharePoint site, but all you can achieve with it, is change the color, text and html element styling etc. You are stuck with the page layout, webpart zones and available web parts in your page or template.

  2. Themes. Similar to the above, but in reality I tend to stay away form them.

  3. Templates. The most cumbersome but effective way to brand SharePoint. In my experience I have found this to be the only reliable way to effectively achieve all your branding needs ( coupled with style sheets ).

  4. Onet.xml. This is the only way to customize a site definition. On the branding side it does not help much, except define an alternate header and css files. It is also used to pre-populate webpart zones with webparts on site creation.

I do not recommend any of our clients to use frontpage with SharePoint and hence tend to steer clear with anything that has to do with Frontpage. Will post more on my recommendations on how best to effectively brand your portal / site in coming articles.

Category : SharePoint

removeAlerts is undefined

February 20th, 2006 // 5:53 pm @

While working with SharePoint templates, if you come across a javascript error, saying “removeAlerts is undefined”, then you have accidently knocked off <SPSWC:AlertsSecurityCheck runat=”server”></SPSWC:AlertsSecurityCheck> from the template page. Put that back in to make life easy :)


Edit: Somehow my code got lost when wordpress autoformatted this post when I migrated from DotNetJunkies. It is corrected now.

Category : SharePoint

Get a list of all Top Level Sites in WSS

February 20th, 2006 // 5:52 pm @

If you have a WSS site with SelfServiceSiteCreation turned on, or you are creating sites programatically using SelfServiceSiteCreation process, it does not create subsites under the root WSS site. Instead it creates top level sites under the Virtual Server under which your root site exists. If you want a list of all such top level sites existing under a WSS Virtual Server, you can use the command line stsadm.exe -o enumsites -url http://WssSiteUrl


But… what if you want to get this list programatically. You cannot get this info from enumerating the subsites or subwebs of the root WSS site. In order to get it, you will need the help of the SPGlobalAdmin class. This piece of code might come handy. The code is in VB, but can easily be ported to C#

Private Sub ListTopLevelSites(ByVal RootUrl As String)

   Dim
globalAdmin As SPGlobalAdmin
   globalAdmin =
New SPGlobalAdmin

   Dim
virtualServer As SPVirtualServer
   virtualServer = globalAdmin.OpenVirtualServer(
New Uri(RootUrl))   Console.WriteLine(“Found ” & virtualServer.Sites.Count & ” sites”)   For Each site As SPSite In virtualServer.Sites
      Console.WriteLine(site.Url.ToString())
   Next

End Sub


For SPS it will not list the sites under the Site Directory ( which can be obtained using the Topology Manager ). Instead it will list the MySites created on the portal.

Category : SharePoint

Extending SharePoint Pages

February 20th, 2006 // 5:48 pm @

Just wanted to make a quick blog post. Will try to post a detailed walkthru later on. I just successfully extended some of the pages from the _layouots directory by overriding some of the default methods of the SharePoint dll’s. Had never done this before and so was not sure if it can be done or not. But now I can write confirmed that it can be done. I managed to add additional functionality to some of the aspx pages from the _layouts directory while retaining the existing functionality and also altering the way the existing functionality worked. Both these ways are possible. As long as the assembly is not obfuscated, ( which most of the application page assemblies are not ), then it’s easy to achieve this.

Category : SharePoint

Introduction to Portals and SharePoint 2003

February 20th, 2006 // 5:47 pm @

My latest SharePoint article is up on www.asptoday.com . It focusses on Introducing Sharepoint to .NET developers. However, non developers will also find the article informative. So if you want to know what SharePoint is and what features good or bad exist, then head over to http://www.asptoday.com/Content.aspx?id=2372 .


As always, comments are always welcome. Any suggestions and constructive criticism is welcome :)

Category : SharePoint

"Cannot complete this action" in SPRequestInternalClass.RenderListProperty for document library templates

February 20th, 2006 // 5:43 pm @

If you come across an error saying “Cannot complete this action” when trying to modify the document library template pages, with an exception trace showing a crash in SPRequestInternalClass.RenderListProperty, you have hit an issue similar to KB 901259.


I had a webpart which built a navigation tree by querying the subsites and document library subfolders under any site. As soon as I put them on the allitems.aspx page under the c:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\1033\STS\LISTS\DOCLIB folder, I started receiving this error. Strangely when I placed the control at the end of the existing page it worked.


My code was as follows :



SPWeb currentWeb = SPControl.GetContextWeb(Context);


string currentSiteUrl = currentWeb.Url;


SPListCollection splstcol;
currentWeb.Lists.IncludeRootFolder = true;
splstcol = currentWeb.Lists;


If I placed my control before any calls to the or any such control which queried list properties, I was getting the above error.


The reason from what I figured out, is that SharePoint gives the reference to the current object when obtained from the GetContextWeb method. When I tried to set the IncludeRootFolder = true, I ended up modifying the properties of the current web object, and this somehow caused an internal crash whenever sharepoint tried to query list properties via calls to controls such as on the page. So when I placed my control at the end of the page, after all such controls it worked, but when any such ListProperty was queried after my control ran, it crashed.


The solution to overcome this problem was very simple. Do not get the existing object references, but create your own instance of the objects. So after modifying the code as follows, everything started working as it should be.



SPSite mySite = new SPSite(SPControl.GetContextWeb(Context).Url);
SPWeb currentWeb = mySite.OpenWeb();


string currentSiteUrl = currentWeb.Url;
SPListCollection splstcol;
currentWeb.Lists.IncludeRootFolder = true;
splstcol = currentWeb.Lists;


I haven’t checked to see if this happens on other such template pages, but in case it does, I guess the solution should be quite straightforward.

Category : SharePoint

SharePoint Active Directory User Creation Mode

February 20th, 2006 // 5:39 pm @

Been playing around with SPS AD Creation Mode and was disappointed to find that it has a lot of limitations. Not sure if I am completely right on this. Might be something that I missed. Just spent a few hours on it. Correct me if I am wrong.



  1. Could not see any sign of AD Creation Mode on SPS. Seems like it is a WSS only feature.

  2. Once I installed WSS using AD Creation Mode, I was unable to create top level sites, or new users from the GUI or Central Admin. Have to use STSADM for creating them using command line.

Was very excited to see if I can use AD Creation Mode to give access to the SPS Portal for internet users to register and create their own accounts. But I guess it is not possible. Have to implement this using custom code using the DirectoryServices classes of .NET.


Correct me if I am wrong on this, and if it is possible to use AD Creation Mode with SPS and let authorised users create user accounts in the ADS using the Central Admin GUI.

Category : SharePoint

DataView Web Part Namespace

February 20th, 2006 // 5:22 pm @

I came acorss a nice link while browsing the newsgroups today. Serge van den Oever has posted on his blog, a nice analysis of the DataView Web Part and the namespaces available inside the dll’s. Look up this fantastic piece of analysis here.


Posted at DotNetJunkies on Monday, January 03, 2005 6:52 AM

Category : SharePoint

Latest Posts

Testimonials

"Amar clearly has a thorough knowledge of Sharepoint, this knowledge, coupled with his professionalism and dedication made him a tremendous asset to the project. He was the key contributor to the later stages of the project delivery effort (the really difficult bit, long hours and hard work that puts huge demands on people), and I can state categorically that without his focussed dedication and hard work we would not have been able to meet the timescales imposed upon the project."

Tim Ellis , Sharepoint Project Manager , Royal Bank of Scotland

Subscribe Now