woensdag 13 oktober 2010

Advanced urlaction tokens for SharePoint

Urlaction tokens can be used to construct URL's that contain some special SharePoint variables that are filled in at runtime. For example, if you want to create a custom action for the ECB that points to your custom ASPX page to do the logic, that page will probably need some parameters so it knows on which item the action was initiated. Such a URL can be constructed using these urlaction tokens. These are the ones you can use:

{ItemId} item.ID.ToString()

{ItemUrl} item.Url

{SiteUrl} web.Url

{ListId} list.ID.ToString("B")

{RecurrenceId} item.RecurrenceID


These tokens are well known to developers but did you also know that you can go a step further ? Take a look at the following CustomAction:

<>
Id=" ECBItemCustomization"
RegistrationType="List"
RegistrationId="101"
Location="EditControlBlock"
Sequence="106"
Title="Navigate to Site Settings">
< url="/_layouts/Settings.aspx">
< /CustomAction>

This custom action will add a new ECB button for each list of type 101. What's important here is the Url parameter of the UrlAction. In this example, the Url parameter is static. But most of the time you want to do something like this:

< url="/_layouts/Settings.aspx?siteurl={SiteUrl}&listid={ListId}&itemid={ItemId}">

With this information you can find a reference to the list item in your ASPX page and do anything you want with it.

Now if we go one step further, we can even use javascript in this url. You can for example use variables and simple expressions. Take a look at the following example:

< url="javascript: var absurl={SiteUrl} + {ItemUrl}; window.location='/_layouts/Settings.aspx?siteurl={SiteUrl}&listid={ListId}&itemid={ItemId}&itemAbsUrl=' + absurl + '&source=' + window.location">

As you can see I created a variable absurl which I can then use later in my URL. Later on, I also used window.location expression so I can add a 'source' url parameter which tells the system where the user came from so we an easily return.

2 opmerkingen:

  1. Thanks for the nice example. Because I'm still new in this area: can you provide also a little example how to consume the custom action and to use the parameters?
    Thanks, Ulf

    BeantwoordenVerwijderen
  2. var absurl={SiteUrl} + {ItemUrl};
    above line not work. {ItemUrl}contains part of site url.

    BeantwoordenVerwijderen