Archive | August 2010

Impersonation in Sharepoint 2007

Found out a good article , that answers when and how to impersonate in sharepoint 2007 .

http://vspug.com/tanujashares/2007/08/07/impersonation-in-sharepoint-2007/

Advertisements

Customise the navigation in Sharepoint

We can customise the navigaiton in a sharepoint site using the WSS V 3.O navigation store , that is represented by the namespace Microsoft.Sharepoint.Navigation .
It provides classes ,properties and methods to customise the navigation of a sharepoint site .
lets see how to add a custom link to a quick launch bar /top navigation bar on activating a feature
class CustomLinkQuickLaunch : SPFeatureReceiver
{

//Get the context of the current site
SPSite oSite = SPContext.Current.Site;
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{

using(SPWeb oWeb = oSite.OpenWeb())

{
//Get the tree view colllection of nodes in the quick launch bar
SPNavigationNodeCollection nodeColl=oWeb.Navigation.QuickLaunch;

//Get the tree view colllection of nodes in the top navigation bar
SPNavigationNodeCollection nodeColl=
oWeb.Navigation.TopNavigationBar;
//Add a new node to the collection giving it a titel and url , boolean value indicates whether the link is outside the current site coll or not .Since ,it is outside the current site coll we pass boolean true here
SPNavigationNode oCentralAdminNode =

new SPNavigationNode(“Central Admin Home “, “url of the central admin”,true);
nodeColl.AddAsLast(oCentralAdminNode);

//Now we can add a child node to the central admin link in a simialr fashion
SPNavigationNode oExtNode = new SPNavigationNode(“Yahoo Home “, “http://www.yahoo.com/”, true);
oCentralAdminNode.Children.AddAsFirst(oExtNode);
oWeb.AllowUnsafeUpdates = true;
oWeb.Update();

}
}
We need to delete the node from the quick launch bar/top navigation bar on feature deactivation , it will create a duplicates entry of the nodes when activated for the next time otherwise .The following code does exactly this

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
using(SPWeb oWeb = oSite.OpenWeb())

{
//Get the node collection of the quick launch or top navigation bar
SPNavigationNodeCollection nodeColl=oWeb.Navigation.QuickLaunch;
SPNavigationNodeCollection oNodeColl = oWeb.Navigation.TopNavigationBar;
oNodeColl.Delete(indexing to the node collection can be done to get a node to be deleted)

oWeb.AllowUnsafeUpdates = true;
oWeb.Update();

}
}
}

Difference between Custom templates and Definition in Sharepoint

Custom templates here refers to Site/List templates while definition refers to Site/List definitions .Let me point out the key differences that helps us in our design decision ,

Templates –
Custom templates are created from the existing site /list through UI, that may or may not have contents .
Templates exists in the database .
Templates cannot be changed for further use and has to be used the way it is.
They are typically easy to create and deploy .

Definitions –
We create custom definitions by declaring the lists, fields, web features, site features ,content types ,navigation bars to be added with a site/list and registering them ,so that they can be used readily.
They exists in the web server (file system) ,hence better performance .
They can be customised and modified as & when required .
Not easy to create and deploy .
One has to have access to the Web server for deploying the definitons.