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. )
-
Property: get the value of the field property such as name and custom properties (eg. )
-
ListProperty: get the value of the list property (eg. )
-
ProjectProperty: get the value of the web property (eg. )
-
URL: get the URL for a specific Command (eg. )
- ...
Invaluable tools and resources
Download
-
SharePoint 2007 Solution (WSP)
-
Visual Studio 2008 Code Solution
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 :)