June 20, 2008 - 17:24, by Steven Van de Craen
Categories: .NET, SharePoint 2007, Custom Field Types
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 :)
June 4, 2008 - 12:06, by Steven Van de Craen
Categories: .NET, SharePoint 2007
Description
Here's a small solution for those of you lucky enough to have MOSS 2007. It will not work if you only have WSS 3.0 installed.
This project will add a browse button to all Link fields in your SharePoint Lists by using the AssetUrlSelector control. For more information about this see: Working with the AssetUrlSelector
Screenshot
Before:
After:
Download
-
Assembly, browser-file and instructions
-
Code project (VS 2008)
Installation
The installation instructions are contained in the download above. Deploy the browser file to the App_Browsers folder of the SharePoint Web Application (IIS Web Site) and drop the assembly in the GAC.
Note: I have been getting comments about the button not appearing. The issue seems to be related to the App_Browsers\compat.browser file. Just open that file in Notepad and save it. This somehow forces the Web Application to reload all browser files and the button will appear.
Note: If you have multiple browser files already you might have to repeat the above step for each of them...
Requirements
This functionality uses the Publishing features in MOSS 2007 and will not work on a WSS 3.0 only environment.
Notes
Feel free to modify or improve the code.
No need to reconfigure your Lists or Columns. It is active on all existing and new fields as soon as you have run through the deployment.
I couldn't get the browser-file working with a WSP file (using WSPBuilder) so the deployment is still a manual process.
June 4, 2008 - 08:02, by Steven Van de Craen
Categories: .NET, SharePoint 2007
I'm doing some tests with the AssetUrlSelector control to improve user experience in a SharePoint 2007 environment.
The AssetUrlSelector control gives your end users a nice interface for selecting a link or image URL from a site collection. You can read the MSDN documentation here:
AssetUrlSelector Class (Microsoft.SharePoint.Publishing.WebControls)
By default it renders a textbox and a button which gives you the selection interface but you can also bind it to your own controls. In the latter case you can hide the default textbox and/or button. Both scenario's are neatly explained in the MSDN docs (see link above).
Here's a quick sample of using the AssetUrlSelector in a WebPart:
public class BrowseButtonWebPart : WebPart
{
protected override void CreateChildControls()
{
Label lblUrl = new Label();
lblUrl.ID = "lblUrl";
lblUrl.Text = "Url: ";
Controls.Add(lblUrl);
TextBox txtUrl = new TextBox();
txtUrl.ID = "txtUrl";
Controls.Add(txtUrl);
AssetUrlSelector picker = new AssetUrlSelector();
picker.ID = "ausUrl";
picker.AssetUrlClientID = txtUrl.ClientID;
picker.AssetUrlTextBoxVisible = false;
Controls.Add(picker);
}
}
And this is the result on screen:
Note that it's only available in MOSS 2007 since it's part of the Microsoft.SharePoint.Publishing namespace !