Friday 2 April 2010

Use the SPWebCategoryName attribute instead of the System.ComponentModel.Category attribute to group web part settings

For some reason I’ve always used the System.ComponentModel.Category attribute to configure the category or group under which a web part property is displayed when viewing the web part’s settings. This approach always worked fine but it also felt a little dirty—especially because I always knew an alternative existed (but was never certain what that alternative might be ;-)

At long last I’ve determined the alternative to be the SPWebCategoryName, which works identically to Category:

[Personalizable(true),
WebBrowsable(true),
SPWebCategoryName(“My Category”),
WebDisplayName(“My Property”),
WebDescription(“My property description.”)]
public string MyProperty ( get {…} set {…} )

The SPWebCategoryNameAttribute type lives in the Microsoft.SharePoint.WebPartPages namespace so you’ll need to add a using statement or fully-qualify the type name.

No comments:

Post a Comment

Spam comments will be deleted

Note: only a member of this blog may post a comment.