Tuesday, March 31, 2009

Change the Regional Setting of Site

You could change the regional setting of the site by browsing to Site Actions > Site Settings > Regional Settingsimage

You could also change the Locale using the following code:

using (SPSite site = new SPSite("http://SITE"))
    using (SPWeb web = site.OpenWeb())
        SPRegionalSettings newRegionalSettings = new SPRegionalSettings(web);

        // Change to Australia
        newRegionalSettings.LocaleId = 3081; 
        web.RegionalSettings = newRegionalSettings;

Friday, March 27, 2009

In-Line Script in SharePoint Page

You could add in-line script to a SharePoint page or Page template.

<asp:Content ID="main" runat="server"  ContentPlaceHolderID="PlaceHolderMain">
<% Response.Write("Hello Sanjay Sansanwal"); %>

You would able to access this page without error provided this page is ghosted(uncustomised) as WSS complies a ghosted page into an assembly DLL for processing.

But if you customise this page or open in SharePoint,  SharePoint safe mode don’t allow this and you would get error “Code blocks are not allowed in this file”.

You could force SharePoint to allow in-line scripts in customised pages by adding following to the web.config

  <SafeMode ... >
          AllowServerSideScript="true" />

Note: You should avoid doing this as it compromise SharePoint security. In-Line scripts are not allowed in customised pages so that unwanted user could not write malicious code to hack the system.

Add a custom menu to the list

Change the elements.xml described in last blog posting to add a menu item to the menu which appears when you edit a document item

<CustomAction Id="ListMenuForMyPage"
  Title="My Page" >

  <UrlAction Url="~site/_layouts/CustomPages/MyPage.aspx?ItemId={ItemId}&amp;ListId={ListId}"

This CustomAction element is different than what you have seen before because it has a RegistrationType attribute that is assigned a value of List. It also is configured with a RegstrationID attribute that is assigned a value of 101. Note that 101 is a list type identifier that applies to all document libraries. You should also notice that the Location attribute has a value of EditControlBlock, which creates the effect of adding the menu item to the ECB menu of documents within a document library.

Note the {ListId} token and the {ItemId} token within the UrlAction Url’s QueryString. MOSS dynamically replaces them  with list GUID and itemId

Add Custom Action to SharePoint Site

Create a new feature which copy custom page(My Page) to the layout\CustomPages folder. Add the following in the elements.xml to create a custom action item.

<!-- Add Command to Site Actions Dropdown -->
<CustomAction Id="SiteActionsToolbar"
  Title="My Page"
  Description="Browse to my custom page"
   <UrlAction Url="~site/_layouts/CustomPages/MyPage.aspx"/>

This would add a new menu called “My Page” to the Site Actions menu.

When creating a CustomAction element, you can configure the URL attribute of the inner UrlAction element by using the ~site token, as you have just seen. You could also use ~sitecollection token in cases in which custom page should always be executed within a URL associated with the current site collection and its top-level site.

To restrict this page to only viewable to administrator, add RequireSiteAdministrator attribute to CustomAction and set it to “True”. For more security, add the following code in the “My page” custom page -

protected override bool RequireSiteAdministrator {
    get { return true; }

Find PublicKeyToken of signed assembly

To find the publickeytoken of an assembly, I use to drag and drop the assembly to C:\Windows\Assembly folder and then view the properties.

The better way is to use SN.EXE located under “C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin” folder.

You could integrate this tool into VS IDE using external tool features.

  1. In Visual Studio 2005, click Tools -> External Tools...
  2. Click Add and enter the following into the different fields as displayed in the following screenshot:
    • Title: Get Public Key
    • Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe
    • Arguments: -Tp "$(TargetPath)"
    • Uncheck all options, except Use Output window\

Now, you have a new entry listed in the Tools menu titled Get Public Key as shown in the following screenshot:






Assuming you have a project open that has been configured to be signed when built, and you've built it at least one time, selecting the new Get Public Key menu item from the Tools window to get the public key token and blob in the Output window.





Here you have assembly publictokenkey in second entry

Missing Create GUID Tool from Visual Studio 2005

I created a new VM and installed Visual studio 2005. To my horror, I could not found the Create GUID tool in Visual Studio.The Create GUID tool is often found under the Tools menu.

To fix this, I performed the following steps:

  • Reset my IDE settings.
    Select "Tools --> Import and Export Settings --> Reset All Settings" to restore the defaults. Woh, I could see the Create Guid in tool. But, it was disabled :-(

The actual file for generating GUID is guidgen.exe which would be located at “C:\Program Files\Microsoft Visual Studio 8\Common7\Tools”.

I realised that this file is missing as I didn’t installed Visual C++. I was trying to be smart :-)

Wednesday, March 25, 2009

MOSS Filter web parts Not found

To add filter web part to your web part list:

1. Click on the new button in the web-part gallery and select the correct classes from web part gallery

2. If you can’t find them in web part gallery, upload the Web Part definition files from %CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\BizAppsSiteTemplates\dwp.

For more information about Filter web part Click here

Filter MOSS custom list view based on User Profile properties

MOSS 2007 comes with a number of filter web parts that makes it really easy to filter your SharePoint lists by connecting filter web parts with list view web parts.

Note: These are only available in MOSS enterprise edition and could only be applied to “All Items” view or to view configured as “Standard View” type

I would walkthrough in this tutorial to filter a list items based on User Location (mapped to Office profile property in the User Profile repository).


There are list of courses stored in a custom list called “Courses”. The requirement is to display courses only available in current logged user’s location.  The easiest way would be to create a view on the list and set the filters. Ironically, there is not inbuilt [Location] attribute like [Me] or [Today]. You could filter the view on [Me.Office] as shown below


The other way is to use the Current User Filter. With the Current User Filter you can filter the contents of web parts by using any property of the current user.


1.      Create a List called Courses





Name of Course


Detail about the course


Name of instructor


City where course would be held

2.      Add couple of items to this list with different location. Make sure one record have location same as your location. In this example, current user’s Office profile property has value as “Melbourne”.


3.      As the list page is a web part page, you could easily add web parts to this using User Interface.

4.      Click Site Actions -> Edit Page

5.      On the top of the list, click “Add a new Web part” and select web part “Current User Filter”


6.      Edit the newly added web part “Current User Filter” by clicking Edit -> Modify Shared Web part

7.      Click “SharePoint profile value for current user” and select “Office” from dropdown


8.      Press OK.

9.      Now, we need to make a connection between this web part and courses list. On “Current User Filter” web part, click Edit -> Connections and Select Courses


10.   You would be prompt with a dialog box, select the List field which need to be mapped to the User’s Office attribute.


11.   Click Finish and Exit the edit mode. You would now only see the items in list which have location same as your Office.



Tuesday, March 17, 2009

MOSS Ghosted and Unghosted Experience

In last project, I managed a large MOSS project consisting of around 30 developers span across two countries. On first deployment to SIT, we found that UI changes have not gone to SIT environment. We could see the changes in the Source control and on the actual files in the file system of deployment server.

To verify, I added “Hello World” text to the physical file located under our site definition. The changes were not reflected on the application home page. This testing proved that the our custom site definition pages have been unghosted(customised) and have current instance in the database.

We found that developer have used SharePoint Designer to customise these pages and hence they been unghosted. We ghosted(un-customised) them by going to Site Actions –> Reset to Site Definition. Once done, we were able to see the changes on our application. This process is called Reghosting == Changing from Customized to Un-Customized

To stop this to happen again, we restricted SharePoint Designer access to ONLY development environment. All the customize changes went through to other environment using SharePoint Package as described in my previous blog entry “Customise SharePoint List forms – Part 2

Note: Reverting pages to their original ghosted state will destroy existing page content and meta info.  It is highly recommended that you make a backup copy of a page before resetting the page.

Customise SharePoint List forms – Part 2

In Part 1, I walkthrough modifying the display form of the list by adding headers. This was achieved using SharePoint Designer.  This is easy to do on development machine but how would you do this on Test or Production environment. You would not be able to connect to this environment using a developer tool. If you are in your organization, please avoid as this is not good practice. Opening pages using SharePoint designer would un-ghost your custom pages (add to database). If you install the changed pages using SharePoint solution, your application would read from database and not from file system.

To deploy a custom dispform to the production environment, you need to create a WSP package.


1.      Create List Instance Schema:

The best tool which REALLY does a job is Imtech StsAdm Commands. Download it from http://www.codeplex.com/imtech/Release/ProjectReleases.aspx?ReleaseId=10875

2.      Install Imtech STSAdm package to your development server

3.      The command sytax is

stsadm.exe -o ocdexportlist

           -url <url of the site containing the list>

           -name <list name>

           -dir <export location>


This action exports the definition of a list with the given Name


stsadm.exe -o ocdexportlist -url http://sharepoint –name Employee -dir C:\EmployeeList\



4.      Run the command changing the text in red according to your environment

5.      This would generate following files –



The XML which describes the list instance


Display form based on the List


New form based on the List


Edit form based on the List


Form which displays the default view(All Items)


6.      Create Elements.xml and Feature.xml files(Check Microsoft site for creating them).They are simple XML file which contains the feature information

7.      Create a SharePoint Package and add the files to the project

8.      Build the solution and deploy on production site. You should now have a list called Employee and having headers in Display form for the item.