Sharepoint Insight by Namwar Rizvi

Sharepoint Tips, Tricks and inside knowledge from real world experience by Namwar Rizvi

How to dynamically construct the SharePoint site relative url in JavaScript

Posted by namwar on January 1, 2010


There are times when you want to dynamically construct a SharePoint site relative Urls e.g. if you are calling a SharePoint webservice from JQuery etc. then you will need to call it in context of your required site.

Most people try to slice and dice the URL of the current page and try to find the SharePoint site from it. This is not a very clean way of doing it.

The more easy and clean way is the way SharePoint itself does which is using the JavaScript variable called L_Menu_BaseUrl

This variable holds the relative url of current site.

So for example, if you want to call Lists.asmx for

http://yourintranet/sites/Finance/ then

L_Menu_BaseUrl + ‘/_vti_bin/Lists.asmx’ will give you the required url for web service.

Posted in JavaScript | Tagged: , , | Leave a Comment »

Reverse Engineer the Schema of any List in SharePoint

Posted by namwar on December 26, 2009


If you have ever designed a custom list then you may already felt the pain of creating the schema of it and writing the whole CAML. Sometimes, we just need to enhance an already existing list by creating our own custom list for which we want to copy the existing schema and do the necessary changes.

You can retrieve the schema of any list by using the owssvr.dll call from your browser. Following is the syntax

http://<YourServer>/_vti_bin/owssvr.dll?Cmd=ExportList&amp;List=<YourListGuid>&#8221;

By replacing the Server and List GUID in above url will return you the XML Schema of the list.

To make thing easier, I have created a Feature to add a custom action in Settings menu called “Display Schema“, Click it and you will get the schema of the list.

Steps to create the feature:

1. Create a new folder called “DisplaySchema” in Features folder.

2. Create Feature.xml file and paste the following code

<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="{A66E6CBA-8EA1-4c28-B233-52B3D7FF352B}"
    Title="Display List Schema"
    Description="This feature adds a custom menu item in Settings menu to display List Schema"
    Version="1.0.0.0"
    Scope="Site"
    xmlns="http://schemas.microsoft.com/sharepoint/">
  <ElementManifests>
    <ElementManifest Location="Elements.xml" />
  </ElementManifests>
</Feature>

3. Create Elements.xml file and paste the following code

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- List Toolbar Settings Menu Dropdown -->
  <CustomAction Id="DisplayListSchema"
    RegistrationType="List"
    GroupId="SettingsMenu"
    Location="Microsoft.SharePoint.StandardMenu"
    Sequence="1000"
    Title="Display Schema"
	Description="Displays schema of the list">
    <UrlAction Url="~site/_vti_bin/owssvr.dll?Cmd=ExportList&amp;List={ListId}"/>
  </CustomAction>
</Elements>

4. Install the feature by using stsadm command line tool.
5. Activate it.
6. Navigate to any list, Document Library, Tasks list etc. and click Settings, and then click Display Schema.
You will get the schema of that list. Copy it and enjoy!

Posted in Customization, Feature, Solutions, Tips, Tools | Tagged: , , , | 2 Comments »

List of all possible Content Place Holders of SharePoint

Posted by namwar on December 21, 2009


For a handy reference I am listing all possible Content Place Holders in SharePoint pages. This list is obtained from here

Content placeholder Description
PlaceHolderBodyAreaClass Additional body styles in the page header
PlaceHolderBodyLeftBorder Border element for the main page body
PlaceHolderBodyRightMargin Right margin of the main page body
PlaceHolderCalendarNavigator Shows a date-picker for navigating in a calendar when a calendar is visible on the page
PlaceHolderFormDigest The “form digest” security control
PlaceHolderGlobalNavigation The global navigation breadcrumb
PlaceHolderHorizontalNav Top navigation menu for the page
PlaceHolderLeftActions Bottom of the left navigation area
PlaceHolderLeftNavBar Left navigation area
PlaceHolderLeftNavBarBorder Border element on the left navigation bar
PlaceHolderLeftNavBarDataSource Data source for the left navigation menu
PlaceHolderLeftNavBarTop Top of the left navigation area
PlaceHolderMain Main content of the page
PlaceHolderMiniConsole A place to show page-level commands, for example, WIKI commands such as Edit Page, History, and Incoming Links
PlaceHolderNavSpacer The width of the left navigation area
PlaceHolderPageDescription Description of the page contents
PlaceHolderPageImage Page icon in the upper-left area of the page
PlaceHolderSearchArea Search box area
PlaceHolderSiteName Site name
PlaceHolderTitleAreaClass Additional styles in the page header
PlaceHolderTitleAreaSeparator Shows shadows for the title area
PlaceHolderTitleBreadcrumb Main content breadcrumb area
PlaceHolderPageTitleInTitleArea Page title shown immediately below the breadcrumbs
PlaceHolderTitleLeftBorder Left border of the title area
PlaceHolderTitleRightMargin Right margin of the title area
PlaceHolderTopNavBar Top navigation area
PlaceHolderUtilityContent Extra content at the bottom of the page
SPNavigation Empty by default in Windows SharePoint Services 3.0. Can be used for additional page editing controls.
WSSDesignConsole The page editing controls when the page is in Edit Page mode (in the browser, click Site Actions, and then click Edit Page)

UPDATE: An excellent visual reference to above mentioned Content Place Holders can be found here

Posted in Customization, Tips | Tagged: | Leave a Comment »

Displaying only Year in SharePoint Calculated Column

Posted by namwar on November 26, 2009


I wanted to display just the year of a DateTime column of SharePoint. I created a calculated column and set the formula to Year([MyDateTimeColumn]). The result I got was 2,009 ; 2,008 etc. which offcourse incorrect for year. After searching through internet, I found a good article solved my problem.

The correct formula is TEXT(YEAR([MyDateTimeColumn]),”000″)


Posted in Architecture, Customization, Solutions, Tips | Tagged: , , , | Leave a Comment »

SharePoint Foundation 2010 – What is it and What do you need to use it?

Posted by namwar on November 1, 2009


In the upcoming version of SharePoint i.e. SharePoint 2010, Windows SharePoint Services 3.0 has been evolved and got a new name called “SharePoint Foundation (SF)”. This will align it more to other Microsoft technologies like Windows Presentation Foundation (WPF) and Windows Communication Foundation (WCF).

SF extends the feature set offered by WSS 3.0 . It provides you a platform with right tools to build your collaborative web sites. Microsoft has published a paper to describe the business value of having SF 2010. You can read the paper here.

As expected, Microsoft has designed SF2010 for 64bit systems only. There is no 32 bit version of it. Following is the basic requirements list to install SF 2010 as described by Microsoft in the paper mentioned above:

SERVER ENVIRONMENT:

  • Windows Server® 2008 64-bit operating system with SP2 or later, OR Windows Server 2008 R2 64-bit
  • Microsoft SQL Server® 2005 64-bit with SP2, SQL Server 2005 Express 64-bit, SQL Server 2008 64-bit or SQL Server 2008 Express 64-bit
  • Microsoft .NET Framework 3.5 with SP1 installed

CLIENT ENVIRONMENT:

Level 1 Internet browser options for Windows:
  • Windows Internet Explorer® 7 32-bit
  • Windows Internet Explorer 8 32-bit
  • Firefox 3.x 32-bit
Level 2 Internet browser options:
  • Windows Internet Explorer 7 64-bit
  • Windows Internet Explorer 8 64-bit
  • Firefox 3.x on non-Windows operating system
  • Safari 3.x

 

Posted in Tips | 3 Comments »

Custom Edit Form for SharePoint Lists

Posted by namwar on October 21, 2009


If you want to set a custom edit form to your Sharepoint List then please make sure you follow these Golden Rules as correctly suggested by Hugo in a SharePoint news group.

  1. NEVER delete or rename the default pages…
    when you want to create a new EditForm.aspx it’s best to copy it to
    another file and then edit the original one (without renaming it and
    without reassigning the supporting files)…
  2. DON’T ever delete the webparts that exist.
    It’s better to hide them and create new ones “side-by-side”.

These rules are real time savers and I will highly encourage every reader to follow them.

Posted in Customization, Errors, Tips | Tagged: , , , | 1 Comment »

How to use Case statement in RenderPattern of a Custom Field Type

Posted by namwar on October 14, 2009


While designing a custom field type, you may sometime need to render different HTML based on the value of field. For example, if you want to display Red,Amber, Green traffic light images to highlight High,Medium, Low value then you need to dynamically switch image url based  on the value of the field.

In CAML, you have Case structure to implement this switching logic. It works very much like the C# switch-case statement. Following is an example of RenderPattern of a custom field which display different images based on the value of the field.

<RenderPattern Name="DisplayPattern">
      <Switch>
        <Expr>
          <Column />
        </Expr>
        <Case Value="1" >
          <HTML><![CDATA[<img alt="Red" src="/_layouts/IMAGES/ewr210m.gif" />]]></HTML>
         </Case>
        <Case Value="2" >
          <HTML><![CDATA[<img alt="Amber" src="/_layouts/IMAGES/ewr211m.gif"]]></HTML>
        </Case>
        <Case Value="3" >
          <HTML><![CDATA[<img alt="Green" src="/_layouts/IMAGES/ewr209m.gif"]]></HTML>
        </Case>
        <Default>
            <HTML><![CDATA[<span>No Value</span>]]></HTML>
        </Default>
      </Switch>
    </RenderPattern>

Posted in Tips | Tagged: , , , | Leave a Comment »

SharePoint Designer or Visual Studio?

Posted by namwar on August 1, 2009


If you are confused about when to use SharePoint Designer and Visual Studio then here are some guidelines which may help you choosing the right technology at the right time. The short answer is

Web Designer=SharePoint Designer whereas Web Developer=Visual Studio

  1. First of all please note that these are two completely different tools to solve two completely different types of problems.
  2. SharePoint Designer is focused on Presentation and Branding.  Although, you can some what program a logic to solve some issues (like designing sequential workflows) but it is not good for programming and it is designed to do code free work.
  3. SharePoint Designer is an excellent tool for rebranding the site, customizing the layout, updating CSS and designing Master Pages.
  4. SharePoint Designer can talk to SharePoint natively and can display the pages with full rendering (at least 90%) of web parts.
  5. SharePoint Designer is best suitable for web designers.
  6. Visual Studio 2005/2008 is the tool of choice when you want to extend SharePoint functionality by writing your own custom code.
  7. If you want to design portable workflows, then user Visual Studio.
  8. If you want to create event handlers, custom features, site definitions, custom lists or web parts then use Visual Studio.

Posted in Guidance | Tagged: | Leave a Comment »

SharePoint / WSS 3.0 SQL Database not found error

Posted by namwar on July 21, 2009


While reading the newsgroups, I found a neat solution to share with my readers. If you have deleted content databases of a site collection but you are still getting an error similar to the following in error log

SQL Database ‘WSS_Content_345’ on SQL Server instance ‘DBS1’ not found.

It is because SharePoint config database still has a record of deleted database and trying to connect to it.

Solution:

Run the deletecontentdb stsadm command similar to the following :

stsadm -o deletecontentdb -url http://wss.company.com/sites/name1
-databasename WSS_Content_2

stsadm -o deletecontentdb -url http://wss.company.com/sites/name1

It will delete the old database entry from SharePoint Config database.

Posted in Errors, Solutions, Tips | Tagged: , , , , , | Leave a Comment »

How to display Web Part Maintenance Page in SharePoint

Posted by namwar on July 19, 2009


Often your web part page starts behaving strangely or giving you errors due to some buggy script or web part. This sometimes even stops you to open page in edit mode because of Java Script errors.

Don’t worry, there is a very simple way to delete those web parts. Just append ?contents=1 at the end of the URL of respective page and SharePoint will open the Web Part Maintenance Page for it.

For example, if the URL of problematic page is

http://MOSServer/Test/default.aspx

then Web Part Maintenance Page url will be

http://MOSServer/Test/default.aspx?contents=1


Posted in Solutions, Tips | Tagged: , , | 1 Comment »