CJ

The circle of life – ** .Net – Training – MOSS **

  • Past Post

  • Vistor Locations

CustomAction & UrlAction

Posted by Clayton James on July 30, 2008

Update:
Some more CustomAction elements I have come across include:
– Rights: You can set a Rights property so only people with these rights can view the Custom Action
      Rights=”ManagePermissions”
      You can also remove existing CustomActions based on rights
– RegistrationType and RegistrationId: I have previously set these to lists, however you can even set them to file types. So only files with a .html extension will see this custom action in the ECB menu
     RegistrationType=”FileType”
     RegistrationId=”html”

 

Here is some great information from Jan Tielens Blog.
http://weblogs.asp.net/jan/archive/2007/09/05/using-the-current-page-url-in-the-urlaction-of-a-sharepoint-feature.aspx

I am including the content as I always reference it.

MSDN documentation also.
http://msdn.microsoft.com/en-us/library/ms473643.aspx

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>
    <CustomAction
        Id=”{6FCB0F81-2105-4d9f-96BF-C48A19B8E439}”
        Title=”My Link”
        Location=”Microsoft.SharePoint.StandardMenu”
        GroupId=”SettingsMenu”>
        <UrlAction Url=”_layouts/mypage.aspx”/>
    </CustomAction>
</Elements>

If you build some functionality in the mypage.aspx, in many scenarios this page will need to know from which list the link originated. This can be done by using URL tokens in the UrlAction element:

<UrlAction Url=”_layouts/mypage.aspx?listid={ListId}“/>

The {ListId} URL token will be automatically replaced with the ID of the list, in which the menu item is shown. In the mypage.aspx, you can retrieve the value of the listid parameter by making use of the QueryString. Once you’ve got the ID, the object model can be used to get a reference to the SPList instance of that list. According to the documentation on MSDN, the following URL tokens can be used:

  • ~site – Web site (SPWeb) relative link.
  • ~sitecollection – site collection (SPSite) relative link.
  • In addition, you can use the following tokens within a URL:
    • {ItemId} – Integer ID that represents the item within a list.
    • {ItemUrl} – URL of the item being acted upon. Only work for documents in libraries. [Not functional in Beta 2]
    • {ListId} – GUID that represents the list.
    • {SiteUrl} – URL of the Web site (SPWeb).
    • {RecurrenceId} – Recurrence index. This token is not supported for use in the context menus of list items.

    Unfortunately there is no token that will give you the URL of the page on which the feature’s link is being displayed. In many cases you want to have that URL to be able to redirect, after you’ve shown your custom functionality, to the originating page. SharePoint itself uses this technique a lot: in many URL’s you’ll find the Source parameter:

    http://wss.u2ucourse.com/Lists/Links/NewForm.aspx?Source=http%3A%2F%2Fwss%2Eu2ucourse%2Ecom%2Fdefault%2Easpx

    The URL above points to the NewForm.aspx for the a Links list. Normally when the user fill’s out this form and clicks OK, this page redirects to the default view of the list. Because this link has the Source parameter, when the user clicks OK (or cancel), the page will redirect to the default.aspx instead. You can add the Source parameter to a lot of pages in SharePoint, giving you full control over the redirecting.

    So the issue is: we want to include the URL of the originating page in the UrlAction element of the feature’s CustomAction, but all we get are a bunch of ID’s and some URL’s that are not useful for this scenario. As usual peeking in the machine room of SharePoint itself can give you some good ideas to solve this issue. The SharePoint guys themselves sometimes use Javascript functions in the UrlAction, instead of ordinary hyperlinks. Thus with some clever use of Javascript, it’s quite easy to solve the problem:

    <UrlAction Url=”javascript:window.location= ‘{SiteUrl}/_layouts/mypage.aspx?List={ListId}&amp;Source=’ + window.location”/>

    The actual link is a Javascript function that will navigate to a specific URL. This URL is a concatenation of the URL of the page to display (including for example the ID of the list as a parameter in the QueryString), and the Source parameter which is dynamically set the current page’s URL. Et voila, the constructed link will point to your page, and the redirect will always point to the page you started from.

    Extra: this tric can also be used to overcome a bug in SharePoint that causes a URL token of a CustomAction to be replaced only once. So if you have used the ListID token two times in a UrlAction element, only one of the token’s will be replaced with the actual ID of the list. The user “FlatEric” (what’s in a name?) explains this in the Community Content of the How to: Add Actions to the User Interface article on MSDN.

    I found an ugly way to bypass this flaw:
    <UrlAction Url=”javascript:function process(){var site='{SiteUrl}’;var item={ItemId};window.location.href=site+’/Lists/MyList/NewForm.aspx?ID=’+item+’&amp;Source=’+site+’/Lists/myOtherList/DispForm.aspx?ID=’+item;};process();”/>

  • Advertisements

    19 Responses to “CustomAction & UrlAction”

    1. SSJ said

      How do u add a custom link in the Top link bar using CustomAction tag or rather using feature.

    2. erugalatha said

      Have you come across another bug related to this where Custom Actions on the Document or List Item dropdown menus do not appear when rendered in the Data View Web Part?

      They work fine in the List Form Web Part (default).

      This causes major issues as it breaks the rules whereby items are visible. On the DVWP only 4 items are displayed: View Item, Edit Item, Delete Item and Alert Me. While on the LFWP all items you have access to see are displayed.

      Steps to recreate:
      Edit your AllItems.aspx view in SharePoint Designer.
      Right Click on the List Form Web Part and choose “Convert To XSLT Data View”.
      Save it and view in the browser.
      Dropdown a menu on an item in your list.
      Only 4 Menu Items appear. On the normal view items like “Manage Permissions”, “Workflows” etc. appear.

    3. Deepak Gupta said

      Thanks much for posting this solution!

    4. Grail said

      All good stuff … My problem is I have created a feature to do this, and it works perfectly in WSS 3.0. I try it in MOSS SP1 and it never shows up either functionally or in the Site Collection Feature list. Tried it both on our test MOSS environment and our production. Disappears without a trace … Installs fine, activates fine via STSADM, shows up in some tools, but is missing in the Site Collection Feature list and most certainly doesn’t work …

      Can repeat the install successfully in WSS.

      Any ideas?

    5. Anil said

      How to pass RootFolder to CustomAction UrlAction like we geting ListId

      http://server/_layouts/Upload.aspx?List=ListId&RootFolder=

      I left it empty, what i need to fill in that

    6. frenky said

      gZlVu8 http://gdjI3b7VaWpU1m0dGpvjRrcu9Fk.com

    7. geoge said

      wljDTc http://fnYwlOpd2n9t4Vx6A3lbk.com

    8. Cheap Website Names…

      […]CustomAction & UrlAction « CJ[…]…

    9. Subhash said

      You can use a token called {Source} and it will add the normal Source query paramater that you see SharePoint using.

    10. I’m pretty pleased to find this page. I need to to thank you for your time for this fantastic read!! I definitely loved every bit of it and I have you saved as a favorite to look at new information on your site.

    11. I seriously love your blog.. Great colors & theme. Did you develop this amazing site yourself? Please reply back as I’m attempting to create my own website and want to learn where you got this from or what the theme is called. Appreciate it!

    12. Hello there, I do think your website might be having browser compatibility issues. Whenever I look at your web site in Safari, it looks fine but when opening in I.E., it has some overlapping issues. I simply wanted to give you a quick heads up! Besides that, fantastic blog!

    13. Good blog you’ve got here.. It’s difficult to find quality writing like yours nowadays. I really appreciate people like you! Take care!!

    14. pinterest decor said

      Am i allowed to post your this article to my group in linkedin, if this is ok?

    15. With havin so much written content do you ever run into
      any issues of plagorism or copyright violation?
      My blog has a lot of completely unique content I’ve either authored myself or outsourced but it looks like a lot of it is popping it up all over the web without my authorization. Do you know any ways to help reduce content from being stolen? I’d definitely
      appreciate it.

    16. Fantastic post but I was wondering if you could
      write a litte more on this topic? I’d be very grateful if you could elaborate a little bit further. Thanks!

    17. All you need to do is to coat the chicken by rolling them over
      the seasoning mixture. Preparation method: Take finely chopped onions in a bowl and add yogurt, grated
      coconut, green chili and salt to taste. Essentially the most important portion of
      frying fish is making it possible for the oil to reach the
      best temperature prior to including the fish.

    18. Luciana said

      I’m really impressed with your writing skills and also with the layout on
      your blog. Is this a paid theme or did you modify it yourself?
      Anyway keep up the nice quality writing, it is rare to see a great blog like this one
      today.

    19. If you want to get much from this post then you have to apply these strategies to your won weblog.

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

     
    %d bloggers like this: