Saturday, January 31, 2009

Debugging using CallStack Attribute

Windows SharePoint Services overrides the CallStack attribute. This attribute is located in the Web.config file. The CallStack attribute controls whether a call stack and an exception message are displayed when a system-level exception occurs while ASP.NET processes a request to send a page to all local and remote clients. By default, Windows SharePoint Services disables the CallStack attribute and displays a limited set of exceptions to prevent information disclosure. To receive a call stack and an exception message when an exception occurs, enable the CallStack attribute.

To enable the CallStack attribute
In Windows Explorer, browse to the following folder:

Double-click the Web.config file.
In the Web.config file, search for the <SharePoint> element.
In the <SharePoint> element, locate the
<SafeMode MaxControls="50" CallStack="false"/> tag
and change it to
<SafeMode MaxControls="50" CallStack="true"/>.
Save and close the file.
When exceptions occur, you now receive ASP.NET exception messages with stack trace information.

Note The CallStack attribute enables this functionality for all local and remote clients.

For more information check the source.

SharePoint Dispose Checker Tool

SPDisposeCheck is a tool to help you to check your assemblies that use the SharePoint API so that you can build better code. It provides assistance in correctly disposing of certain SharePoint objects to help you follow published best practice. This tool may not show all memory leaks in your code. Further investigation is advised if you continue to experience issues.

SPDisposeCheck.exe takes the path to a managed .DLL or .EXE or the path to a directory containing many managed assemblies. It will recursively search for and analyze each managed module attempting to detect coding patterns based on the MDSN article and blog post.

It is a console application that takes one parameter which is the path to assemblies to be checked. If you have the PDB symbol file available then the output can include additional source information about the error.


Thursday, January 29, 2009

Install WSS 3.0 SP1 on Vista x86/x64


great post here from Bamboo Solutions. I installed it yesterday and works like a charm.


Find here how to?

Thursday, January 22, 2009

How to add Submenu with Item Template using MenuItemTemplate and SubMenuItemTemplate

Now, how do I add a Sub Item to my Main Menu's... check the below logic. Its fairly simple. So, I took the MainMenu on the Central Admin site and tweaked it little bit.

Open the Welcome.ascx file. I wouldnt recommend doing any modifications on this file because this is a 1 file location and all your sites underneath reflect the modifications you do. So, make a copy... name it as WelcomeNew.ascx file.

and Add these lines below... and see how it works for yourself.

<SharePoint:SubMenuTemplate ID="ID_NewMenuItem" runat="server"
Text="New Item">
<SharePoint:MenuItemTemplate runat="server" ID="ID_SilverLight"
MenuGroupId="100" Sequence="100"
<SharePoint:MenuItemTemplate runat="server" ID="ID_SharePoint"
MenuGroupId="100" Sequence="100"

Silverlight Spy

Its a very nice tool. Use it to beleive it.

Monday, January 19, 2009

Passed MCTS WSS 3.0 Exam # 70-541

I am happy now... finally. Though I have been working on Sharepoint more than year and a half, I never got oppurtunity to get certified. So, this time I decided strong and made sure that I clear this.

Wish me good luck for my future endeavours.

Friday, January 16, 2009

My first glimpse of Windows 7 beta

Its awesome.

I installed it on my laptop (Intel Core Duo, 2GB RAM, 90GB HDD) and its looks like lightning fast. The boot time is phenominal and its very quick in response. I had the CPU meter and its looks pretty cool in consuming resources too.

I installed Microsoft Virtual PC 2007 and added Windows 2008 Server VHD on it. I installed WSS 3.0, VS 2008 on it. Everything running simultaneously ... doesnt even shake any thing on my laptop given its very least configuration.

I would do more of research and would add good findings over here.

However, you got to be little searching to see where are my links on tast bar etc. Just keep in mind that there is a 'right click'.


Wednesday, January 14, 2009

Silverlight for SharePoint - Part I

Finally and Simply,

I just figured out a mechanism to display SharePoint List using Silverlight. There could be many other simple ways, I can just say this is 1 of them. So how did I do it... keep reading...

I wanted to display all the List / Libraries for a given Site.

I created a solution with 2 projects. (I am just jumping into implementation and not adding any basic stuff such as installing Silverlight tools etc)
1. Silverlight project
a. Service References (Which would be our SharePointConnect project)
b. Page.xaml
c. ServiceReferences.ClientConfig
2. ASP.NET Web project
a. crossdomain.xml
b. ISPConnect.cs
c. SPConnect.svc

Lets start with first the SharePointConnect Project.
1. Add a WCF Service file (SPConnect in the above pic)
2. This would essentially add a Interface and the corresponding svc file. Also, add the reference to Microsoft.Sharepoint.dll
3. In the interface, you can add code as show below

using System;
using System.Collections.Generic;
using System.ServiceModel;

namespace SharePointConnect
public interface ISPConnect
void DoWork();

List GetSPListItems(string sUrl);

4. And the real implementation under SPConnect.svc.cs would be some thing like below..

using System;
using System.Collections.Generic;
using Microsoft.SharePoint;

namespace SharePointConnect
public class SPConnect : ISPConnect
public void DoWork()

public List GetSPListItems(string Url)
List sList = new List();
using (SPSite WebApp = new SPSite(Url))
using (SPWeb site = WebApp.OpenWeb())
foreach (SPList currentList in site.Lists)
return sList;

5. By now if you open the web.config you must notice the below. Most importantly notice the basicHttpBinding mode (I would explain it in another post about basicHttpBinding).
<behavior name="SharePointConnect.SPConnectBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<service behaviorConfiguration="SharePointConnect.SPConnectBehavior"
<endpoint address="" binding="basicHttpBinding" contract="SharePointConnect.ISPConnect">
<dns value="localhost" />

6. Add a .xml file to the project named crossdomain.xml and add the below entries.
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "">
<allow-http-request-headers-from domain="*" headers="*"/>

7. Build the project.
8. Now, lets move to the SilverLight Project. When you add the Silverlight project, it would by default add App.xaml, Page.xaml files. So, at this point of time, we will live with them.
9. Right click on References, and choose Add Service Reference.
10. When the Add Service Reference pop's up... Click on Discover and that should display the SPConnect Service that we added to the solution.
11. Give a name to the namespance '... some thing like SharePointConnect.
12. Get a feel of the object browser and look whats in SharePointConnect.
13. Most importantly you would want to concentrate on the methods / events
a. GetSPListItemsCompleted
b. GetSPListItemsAsync
c. GetSPListItemsCompleted
14. The Page.xaml would look like this.

<UserControl x:Class="LearnSL.Page"
Width="800" Height="600">
<Grid x:Name="LayoutRoot" Background="White">
<RowDefinition Height="10" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
<RowDefinition Height="10" />
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="10"/>
<Border BorderBrush="Black" BorderThickness="2" Grid.Row="1" Grid.Column="1" />
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
<Controls:DataGrid x:Name="theGrid" AlternatingRowBackground="Beige" AutoGenerateColumns="True"
Width="800" Height="600" Grid.Row="2" Grid.Column="1" CanUserResizeColumns="True">


15. And the Page.xaml.cs looks like below

using System;
using System.Windows;
using System.Windows.Controls;

namespace LearnSL

public partial class Page : UserControl
public Page()
Loaded += new RoutedEventHandler(Page_Loaded);

void Page_Loaded(object sender, RoutedEventArgs e)

void GetSPList(string Url)
SharePointConnect.SPConnectClient oSPConnectClient = new SharePointConnect.SPConnectClient();
oSPConnectClient.GetSPListItemsCompleted += new EventHandler(oSPConnectClient_GetSPListItemsCompleted);

void oSPConnectClient_GetSPListItemsCompleted(object sender, LearnSL.SharePointConnect.GetSPListItemsCompletedEventArgs e)
theGrid.ItemsSource = e.Result;

16. And finally, the ServiceReferences.ClientConfig file would have the below code
<binding name="BasicHttpBinding_ISPConnect" maxBufferSize="2147483647"
<security mode="None" />
<endpoint address="http://localhost:11284/SPConnect.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_ISPConnect" contract="SharePointConnect.ISPConnect"
name="BasicHttpBinding_ISPConnect" />

17. Now, build the solution and run the Silverlight project and see the output for your self.

In part II I would add some more stuff like how to get specific fields from a SPListt and display in Silverlight grid.

Till then - Have Fun.

Tuesday, January 13, 2009

Get and Update List Programatically (Code)

public void GetAndUpdateList(string ListName, SPWeb site)
// Get List
SPList oSPList = site.GetList(ListName);

// Update List
SPListItem newItem = oSPList.Items.Add();
newItem["Title"] = "New List Added.";
newItem["Body"] = "This is exciting";
newItem["Expires"] = DateTime.Now + TimeSpan.FromDays(1);

// Also you might want to check for the Field Type before updating some times.
foreach(SPField field in newItem.Fields)
if(!field.Hidden && !field.ReadOnlyField)

The Update method of the SPListItem object commits the changes to the list. If you don’t call the Update method, the list item data will not be saved.

GetList is the preferred method to access a list by a URL. GetListFromUrl and GetListFromWebPartPageUrl function the same way as GetList but throw a generic SPException on failure rather than the more descriptive FileNotFoundException.

Programatically get all available list(s) on a site (Code)

public List GetList(string siteUrl)
List sList = new List();
using (SPSite WebApp = new SPSite(siteUrl))
using (SPWeb site = WebApp.OpenWeb())
foreach(SPList currentList in site.Lists)
return sList;

How to Programatically apply custom branding?

Here is a simple small code snippet.
Have Fun.

public void ApplyCustomBranding(string MasterPageUrlPath, SPWeb site)
if(site == null)
site = SPContext.Current.Site.RootWeb;
MasterPageUrlPath = site.ServerRelativeUrl;
MasterPageUrlPath += @"/";

MasterPageUrlPath += @"_catalogs/masterpage/mynew.master";

site.MasterUrl = MasterPageUrlPath;

foreach(SPWeb child in site.Webs)
ApplyCustomBranding(MasterPageUrlPath, child);

Thursday, January 8, 2009

Programatically removing webpart from site collection

I have been working with my friend / colleague regarding the subject. He gave me the direction on how to get this done. Here is the initial blog he submitted.

Now, as some times it becomes a dying situation that you want to execute the same using Command Line tool, following are the points that you need to take into consideration.

1. Verify if the page has only SharePoint WebParts or any custom webparts that you have designed.
2. If you have only SharePoint WebParts then ignore point# 4
3. Check and Create HTTPContext as shown below (this may be required since you will be running outof sharepoint context)

if (HttpContext.Current == null)
isContextNull = true;
HttpRequest request = new HttpRequest("", web.Url, "");
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
Console.WriteLine("Context Created.");

4. Declare all the Assemblies as SafeControls under the app.config incase you have custom controls or webparts that you designed are placed on the page
5. Use the below code...

SPLimitedWebPartManager manager = web.GetLimitedWebPartManager("default.aspx",System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);

foreach(WebPart wp in manager.WebParts)
if (wp != null && wp.Title == "")
web.AllowUnsafeUpdates = false;

6. Make SPWeb AllowUnsafeUpdates = true when you create the SPWeb instance.

Thats it.
Have fun.