IE Developer Toolbar Not Functioning !

I received this question several times from several colleagues who use IE Developer toolbar for skinning SharePoint sites :
“I installed the IE Developer Toolbar but All the menus are in gray and it’s not functioning at all.”
Well, It’s easy :
1) Tools –> Internet options –> Security –> Local Intranet –> Custom Level –> Run ActiveX Control or PlugIn (Administrator Approved)
2)Tools –> Internet Options –> Programs –> Manage add-ons –> IE Developer Toolbar BHO –> Enable
3)Tools –> Internet Options –> Advanced –> Enable third party browser-extensions 4)Restart IE

Happy skinning 😀

We’ll miss you, Patrick.

Patrick Tisseghem, long time SharePoint MVP and co-founder of U2U, a Microsoft Gold Certified Partner, suddenly passed away on September 3rd evening in Gothenburg, Sweden due to heart failure. He is survived by his wife, Linda, and daughters, Anahi and Laura.
On behalf of the SharePoint product group, I offer my deepest condolences to Patrick’s family. Patrick was a leading figure in the SharePoint community, well known for his standing room only presentations at conferences and user group meetings as well as respected for his often sold out in-depth technical training courses.

OWSTIMER ! Memory Leakage

Often the OWSTIMER.EXE process will allocate significant amounts of memory . As more and more memory is allocated to OWSTIMER, less is available for other processes, most notably the Internet Information Server (IIS) web service (W3SVC). If IIS does not have sufficient memory, a serious performance penalty will result. The workaround for this memory leakage to stop and then start the OWSTIMER process. This can be accomplished using the built-in Services application (under Administrative Programs in the Start menu) or via the command line. (The command-line entry is “net stop WSSTimerV3“.) In a large farm deployment, the service will be running on many Web Front Ends ( WFE’s) so the workaround must be performed on all of them.

Hiding SharePoint Site Templates & Adding new categories!

A colleague asked me about removing some of the templates/site definitions that are available when creating SharePoint sites. Actually It’s so simple.
To hide a template from users :

1) Open the Webtemp.xml file located in the the 12 hive /template/1033/XML folder.
2) Change the Hidden parameter of the template(s) you want to hide.

Note also that you can create your own categories by editing the DisplayCategory value

Master Pages Tokens

Hi guys, It’s a little post, but I thought it would be useful for beginners to SharePoint branding.
“Master Pages” is an essesntial topic when it comes to SharePoint Branding as they provide consistency by providing a common layout, content, look and feel across the pages that use them.

Note the reference to the token ~masterurl/default.master in the first line in any sharepoint content page.

When you use the attribut MasterPageFile into your page header, you can give the relative url of the master page you want.
There also some token to give you more options :
Dynamic token :
“~masterurl/default.master”>>> This token references a master page from a content page by using the MasterPageFile attribute together with the value of the MasterUrl property. And this resolves by default to /_catalogs/masterpage/default.master but you can change the MasterUrl property using SharePoint designer or using Master Page page under Site Settings via the browser .
“~masterurl/custom.master”>>> This token references a master page from a content page by using the MasterPageFile attribute with the value of the CustomMasterUrl property . Also it resolves to /_catalogs/masterpage/default.master by default.

MSDN Note : If you subsequently need to delete the default.master file, you must set both of those properties to a different value.
Static token :
“~site/x”>>> This token link to the current site-relative path
“~sitecollection/x”>>> This token link to the current site collection-relative path

For example, if your content page is located at http://myPortal/subsite1/subsite2/default.aspx and you use the token “~sitecollection/mypage.master”, your content page would use the master page athttp://myPortal/mypage.master. If you use the token “~site/mypage.master”, the content page would use the master page located at http://myPortal/subsite1/subsite2/mypage.master .

Tip : It’s also possible to control the selection of Master Pages at run time with .NET code using the page’s OnPreInit method or by using an HttpModule. ( will be discussed in later posts ) .

Be Careful When Using properties & SPContext

What is SPContext ?
In a nutshell, SPContext object can be used to get a reference to the site or the web from the current context, It Represents the context of an HTTP request in SharePoint .
For instance :
SPList currentList = SPContext.Current.List;
SPWeb currentSite = SPContext.Current.Web;
SPSite currentSiteCollection = SPContext.Current.Site;
SPWebApplication currentWebApplication = SPContext.Current.Site.WebApplication;
SPListItem item = (SPListItem)SPContext.Current.Item;
SPUser user = SPContext.Current.Web.CurrentUser;

What is “Properties” ?
The properties object holds information about an event. You can use it to get references to SPSite, SPWeb, SPList or SPList Item.
for instance :
SPListItem item = properties.ListItem’

Be VERY careful when using properties parameter or SPContext. You CANNOT use the properties command to create your objects or your code will fail! .
You need to use properties or SPContext to locate the items, then use the items IDs to create the object references. You will never get your code to work the way it is above.
You need to get all of the Guid identifiers BEFORE entering the secure block ( RunWithElevatedPriveleges) or Impersonation, then create all the objects you need WITHIN the secure context

Guid SiteId = SPContext.Current.Site.ID;
Guid WebId = SPContext.Current.Web.ID;
Guid ListId = properties.ListId;
Guid UniqueId = properties.ListItem.UniqueId;
using (SPSite site= new SPSite(SiteId))
using (SPWeb web= site.AllWebs[WebId])
SPList list= web.Lists[ListId];
SPListItem listItem= list.Items[UniqueId];
// Code..

or to impersonate the system account using SPUserToken ( Recommended )

Guid SiteId = SPContext.Current.Site.ID;
Guid WebId = SPContext.Current.Web.ID;
Guid ListId = properties.ListId;
Guid UniqueId = properties.ListItem.UniqueId;
SPUserToken systemAccountToken = SPContext.Current.Site.SystemAccount.UserToken;
using(SPSite mySite = new SPSite(SiteId, systemAccountToken))
using (SPWeb myWeb = mySite.OpenWeb(WebId))
SPList list= web.Lists[ListId];
SPListItem listItem= list.Items[UniqueId];
// Code..

Where EXACTLY are they stored ?!!!

I used to ask myself , Where exactly are sharepoint documents stored ?
hmm may be on the file system ? no ! Not reasonable..
In the content database ? hmm
After investigating this subject, I found out that every time you save a document in the document library on a SharePoint site, the entire contents of the document is saved in binary format in a single image-type field in the SharePoint database.
WOW, an entire document in a single field ??

When I told a colleague about that he asked me for an evidence.
Ok !

Guys, check this link : , documentation on the Microsoft Developer Network always says the truth 🙂

SPUserToken, The Hero !

A few days ago, I wrote event handler code that runs in the security context of the logged in user. SharePoint security model makes it easy to programmatically execute code within the current user context But there were some situations when the code needs to be executed with permissions greater than that of the current user (like instantiating a site collection or enumerating list permissions ).

In such situations, the code needs to be executed with elevated permission level or under the context of user with higher permissions i.e. Impersonation.
As the MSDN documentation says, SPSecurity.RunWithElevatedPrivelege “Executes the specified method with Full Control rights even if the user does not otherwise have Full Control.”
In my experience with Using SPSecurity.RunWithElevatedPrieveleges, there are too much tricks that you should take care of.
For Instance : You must create the new SPSite objects inside the delegate because SPSite objects created outside do not have Full Control even when referenced inside the delegate. Use the using keyword to ensure that the object is disposed in the delegate. The next example shows this. SPSecurity.RunWithElevatedPrivileges(delegate()
using (SPSite site = new SPSite(web.Site.ID))
{ // Perform elevated actions here
The problem is that the SPWeb object from the current context is initialized using the current user’s credentials, so even though we run the code snippet with elevated privileges the actual access to the file is still restricted. To resolve this we have to create a new SPSite/SPWeb object within the elevated code, where we run in the context of the elevated user. Then we can perform the restricted action. Since the SPSite/SPWeb objects are created explicitly we have to also dispose of them.
There’s too much overhead, too much chances of introducing obscure bugs, too much potential abuse when it comes to using SPSecurity.RunWithElevatedPrievelges.

That’s why I’d recommend to use SPUserToken to impersonate the SYSTEM and use elevated privileges.

Fortunately, the SystemAccount SPUser is a property of any SPSite object. So instead of using SPSecurity.RunWithElevatedPrivelege, you can use the following code to perform elevated actions:

SPUserToken systemAccountToken = SPContext.Current.Site.SystemAccount.UserToken;
using(SPSite mySite = new SPSite(SPContext.Current.Site.ID, systemAccountToken))
using (SPWeb myWeb = mySite.OpenWeb(SPContext.Current.Web.ID))
// Perform elevated actions here

The Evils of AllWebs !

As I have been working to develop an event handler that will be used to mirror a Document Library, I’ve come across an interesting tid bit that was frustrating at first.

It’s worth mentioning that in MOSS 2007, Event Handlers execute in the context of the current user rather than the process user in SharePoint 2003 .

The event handler contained the following piece of code :
using( SPWeb web = SPContext.Current.Site.AllWebs[guid] )
// code

When running as an administrator, the event handler worked fine. However, if you switch to a non-administrative user that doesn’t have full control of the site, you’ll get a lovely exception. The problem is that you must have full control of the site to be able to use the AllWebs property.

To solve this, try the following code:

using( SPWeb web = SPContext.Current.Site.OpenWeb(guid) )
// code

Happy SharePoint Coding 😀