SharePoint WebPart Property Attributes

Fant en god artikkel om hvordan man bruker atributter i SharePoint webparts, så webpartene kan utvikles mer generelt.

Posten (som jeg har hentet fra http://joeshepherd.spaces.live.com/blog/cns!9AE2097A4A610B63!302.entry) har jeg kopiert hit, så jeg har den i «arkivet».

I wanted to put this information out there because it was not well published when I was building WebParts for the first time. When you build a WebPart in MOSS 2007 you have the ability to expose the public properties of the WebPart in the editor pane of the WebPart page. This allows you to set some administrative values for the WebPart behind the scenes. In order to make this happen you have to tag the property as being Web Browsable. Unfortunately most of the documentation only gives information on the WebBrowsable and Personalizable attributes. However there are a few others that you might find valuable to know about. Some of the other attributes are listed below along with explanations and links to further resources.

WebBrowsable [WebBrowsable(True)]
«Indicates whether the designated property of a Web Parts control is displayed in a PropertyGridEditorPart object.» (MSDN) http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webbrowsableattribute.aspx

WebPartStorage [WebPartStorage(Storage.Personal)]
This attribute specifies what type of storage options the WebPart will make use of. The most common is Storage.Personal. «This property can be personalized by individual users. Its WebPartStorageAttribute value is Storage.Personal, which specifies that the property can be stored on a per-user basis. Only users with the Personalize Web Part pages right can set this property.» (MSDN) http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.webpartstorageattribute.aspx

Personalizable [Personalizable(true)]
Allows users the ability to personalize settings for the WebPart. http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.personalizableattribute.aspx

WebDispayName [WebDisplayName(string)]
Defines the Friendly Name for a property of a WebPart control. This is the name that will show up in the editor screen. http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webdisplaynameattribute.aspx

WebDescription [WebDescription(string)]
Defines the string value to use as a ToolTip for a property of a Web Parts control. (MSDN) http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.webdescriptionattribute.aspx

SPWebCategoryName [SPWebCategoryName(string)]
Defines the friendly or localized name of the category of a property in the CustomPropertyToolPartcontrol inside the ToolPane. http://msdn2.microsoft.com/en-us/library/microsoft.sharepoint.webpartpages.spwebcategorynameattribute.aspx

ConnectionProvider [ConnectionProvider(string)]
Identifies the callback method in a server control acting as the provider in a Web Parts connection, and enables developers to specify details about the provider’s connection point. (MSDN) This is used to create connectable WebParts. http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.connectionproviderattribute.aspx

ConnectionConsumer [ConnectionConsumer(string)]
Identifies the callback method in a server control acting as the consumer in a Web Parts connection, and enables developers to specify details about the consumer’s connection point. (MSDN) This is used to create connectable WebParts. http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.webparts.connectionconsumerattribute.aspx

Below is an example of how to use these attributes in your WebPart code.
[WebBrowsable(true),
Personalizable(false),
WebPartStorage(Storage.Personal),
WebDisplayName(«User Name(Domain\\username)»),
WebDescription(«User to display in the WebPart.»),
SPWebCategoryName(«Options»)]
public string UserLoginName
{
    get { return _loginName; }
    set { _loginName = value; }
}

Happy coding!

Legg igjen en kommentar

Fyll inn i feltene under, eller klikk på et ikon for å logge inn:

WordPress.com-logo

Du kommenterer med bruk av din WordPress.com konto. Logg ut /  Endre )

Google+-bilde

Du kommenterer med bruk av din Google+ konto. Logg ut /  Endre )

Twitter-bilde

Du kommenterer med bruk av din Twitter konto. Logg ut /  Endre )

Facebookbilde

Du kommenterer med bruk av din Facebook konto. Logg ut /  Endre )

w

Kobler til %s