View Action Button


Introduction

Don't you just miss the possibility to have buttons on a SharePoint List or Library View similar to an ASP.NET GridView ? You could add Edit or Delete functionality or even cooler things such as navigating to a LAYOUTS page rather than having to use the item context menu drop down:

I've been playing with Custom Field Types in order to have this kind of functionality and I'm offering the result to you for free !!

Solution

The ViewActionButton Custom Field Type allows you to render a button or hyperlink to a Web Relative Url. The Item ID and List ID are automatically appended for each item so the receiving page can interact with them accordingly.

Some standard actions include:

  • Workflows: /_layouts/Workflow.aspx?ID=1&List={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}
  • Version History: _layouts/Versions.aspx?list={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}&ID=1

But you could also provide your own actions via custom LAYOUT pages:

  • Delete item: /_layouts/Vandest/DeleteItem.aspx?ID=1&List={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}
  • Generate PDF: /_layouts/Vandest/GeneratePDF.aspx?ID=1&List={4F56D0B2-1F4E-46FE-A794-5A6BAAC0CACD}

Once installed you can add as many fields of this type as you want and configure them accordingly:

  • Action URL: The Web Relative Url to a page. The field will automatically append the ListID and ItemID QueryString parameters
  • Format: Specify to render either a button or hyperlink
  • CSS-Class: The CSS class for the rendered item. Use this to further style the button or hyperlink

Notes

Issue #1

There were several headaches involved with this project. The first one occurred when I found out that the Custom Property mechanism doesn't really work the way it is supposed to. Normally you declare your CustomProperties in the Xml and then use this.SetCustomProperty(name, value) but there's a huge workaround required to make this work:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1109290&SiteID=1

I'm not using the workaround described as above but I use the saving mechanism from the out of the box field properties...

Issue #2

After that the last remaining obstacle was CAML (Collaborative Application Markup Language). The List View doesn't work with User Controls but requires you to write CAML, HTML and JavaScript and it can be quite scary at first. Good places to start:

  • C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\FLDTYPES.XML (Take a look at the existing fields how they are rendered)
  • http://msdn.microsoft.com/en-us/library/ms443288.aspx
  • For an overview of CAML Variables go here: http://msdn.microsoft.com/en-us/library/ms480526.aspx
    • Quick Reference:
      • GetVar: can be used in combination with SetVar to store variables on the server.
      • Column: when providing the 'Name' it can be used to get the values of other columns for the item (eg. <Column Name="ID" />)
      • Property: get the value of the field property such as name and custom properties (eg. <Property Select="DisplayName" />)
      • ListProperty: get the value of the list property (eg. <ListProperty Select="DefaultViewUrl" />)
      • ProjectProperty: get the value of the web property (eg. <ProjectProperty Select="Url" />)
      • URL: get the URL for a specific Command (eg. <URL Cmd='New' />)
      • ...
Invaluable tools and resources

Download

Installation using the WSP should be a breeze using addsolution and deploysolution. It will place the assembly in the GAC and the resource files in the correct location in the 12 hive.

 

Feel free to use and improve this :)

 


Links to this post

Comments

Friday, 20 Jun 2008 07:49 by Tobias Zimmergren
Hi Steven, Interesting read, will have a look at the code when time is at my disposal. Cheers, keep it up.

Monday, 23 Jun 2008 11:49 by Oliver Wirkus
Hi Steven, cool blog post. I never thought that this can be done with sharepoint. I'll give it a try in the near future. Good work! Regards, Oliver (www.sharepointblogs.com)

Tuesday, 16 Sep 2008 05:42 by Ashish
Hey Steve Great Solution. Now I want to use this on dispform.aspx with the option for navigation which includes 4 buttons (if possible with record indicator i.e. xx of xxx) i.e. First, Previous, Next, Last. So once user on display page, he need not go back to view page, he can navigate the record using this buttons. Is this possible?

Wednesday, 17 Sep 2008 11:34 by Steven Van de Craen
Ashish the blog post is mainly about the column on the view page. If you want to write a custom field type for the dispform you could use a (custom) ASCX control for that, so what you're seeking might be possible.

Wednesday, 29 Apr 2009 07:18 by Fernando
Hi Steven, Thanks for the interesting post. I am wondering if you know the way around to wire up some server side code to the button presented on the list. In my SPS application, I have a list with the collumn "Owner" and "Comment" and I would like to have a collumn with a button "send email" - where the "to" will be the owner and the "subject" will be the comment. Is there anyway I can do that!? Thanks, Fernando

Monday, 4 May 2009 10:27 by Steven Van de Craen
Hi Fernando, might be that you're better of with http://www.moss2007.be/blogs/vandest/archive/2009/03/31/advanced-computed-field.aspx Not sure though.

Monday, 25 May 2009 08:34 by Daan Vloedgraven
Hello Steven, Interesting feature! In a workflow I want that my users edit an excel-doc. However, my users don't understand that they have to use the ‘item context menu drop down’ and then use 'Edit in Microsoft Office Excel' instead of just clicking on the excel'-document. So I'm a looking for a way to make it easier for them. Is your feature a possible solution for this? So I like to add a button which says "edit in Excel". Kind regards, Daan

Tuesday, 26 May 2009 03:17 by Ron Verhoeven
Hello Steven, I don't see this new fields after deploying the .wsp solution. In central admin the solution is 'globally deployed'. However I don't see the items when I edit a column in my document library. I tried the solution on both an English and Dutch SharePoint installation. Kind regards, Ron Verhoeven

Wednesday, 27 May 2009 01:00 by Steven Van de Craen
Daan, you might want to look into the Advanced Computed Field for that. (The 'Edit in' link is a javascript function)

Wednesday, 27 May 2009 01:02 by Steven Van de Craen
Ron, did you try an explicit iisreset ? Do you have multiple servers in your farm ?

Thursday, 28 May 2009 11:54 by Ron Verhoeven
My mistake, forgot that step this time. Its working now. thanks!

Monday, 11 Oct 2010 01:13 by Invoker
Hi Steven. I use source code of you on sharepoint 2010. Its work but when i go to www.sharepoint/listname/form/allitem.aspx . i cant see any hyperlink or button like your second picture. see my picture. Help me pls. http://i224.photobucket.com/albums/dd295/phienphuc/customfield-1.jpg Thanks.

Tuesday, 20 Mar 2012 11:00 by ToeHan
Thank you. Good luck.

CAPTCHA Image Validation