13.07.2015 Views

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

Microsoft SharePoint. Building Office 2007 Solutions in VB 2005 ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

368CHAPTER 10 ■ SHAREPOINT WEB PARTSPublic Class MyWebPartInherits WebPartEnd ClassEnd NamespaceWeb Part PropertiesWell-designed web parts function <strong>in</strong> a variety of different pages because they are configurableby an adm<strong>in</strong>istrator or end user directly <strong>in</strong> the site. This configuration is possible because eachweb part supports a series of properties that can be set <strong>in</strong> the site and read by the web part atruntime. In code, these properties are created <strong>in</strong> the same manner as any property for anyclass with the exception that they have special attributes that determ<strong>in</strong>e their behavior with<strong>in</strong><strong>SharePo<strong>in</strong>t</strong>. The process of creat<strong>in</strong>g a property beg<strong>in</strong>s with a standard property construct.Most properties are designed to be configured directly <strong>in</strong> the portal. Therefore, you mustdecorate the property with different attributes to def<strong>in</strong>e its behavior when a page is designed.These property values are subsequently serialized and saved when the page is processed sothat the property values can be read later when an end user accesses the page. Each of theproperties you def<strong>in</strong>e is decorated with the WebBrowsable, Personalizable, WebDisplayName,and WebDescription attributes.The WebBrowsable attribute is a Boolean value that determ<strong>in</strong>es whether the built-<strong>in</strong> Share-Po<strong>in</strong>t property edit<strong>in</strong>g pane can access the property. You may set this value to either True orFalse. Although most of your properties will be browsable, you may have sensitive propertiesthat should not be accessible by general users. Additionally, when you create a custom propertyeditor later <strong>in</strong> the section titled “Custom Editor Parts,” you will set this value to False.The Personalizable attribute is an enumeration that determ<strong>in</strong>es whether the propertyvalues are saved for an <strong>in</strong>dividual or for all users of the page on which the web part sits.This attribute may be set to PersonalizationScope.User or PersonalizationScope.Shared.When the attribute is set to PersonalizationScope.User, the property value may be set foreach user of a page. The web part <strong>in</strong>frastructure serializes and saves the values separatelyfor each user. When the attribute is set to PersonalizationScope.Shared, the web part <strong>in</strong>frastructuresaves only a s<strong>in</strong>gle value of the property that is applied to all users of the page onwhich the web part sits.Once you understand the property def<strong>in</strong>ition scheme, you can create as many as youneed to properly configure the web part. Although they are easy to change, I recommend thatyou spend some time design<strong>in</strong>g your web part before implement<strong>in</strong>g the property set. If youth<strong>in</strong>k through the <strong>in</strong>tended use of the web part, you will save yourself a lot of wasted timewrit<strong>in</strong>g and rewrit<strong>in</strong>g property structures. List<strong>in</strong>g 10-2 shows a complete property def<strong>in</strong>itionfor a database connections str<strong>in</strong>g that can be set by a user and then utilized by the web part.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!