RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Use the Power of Reflection to Dynamically Set SharePoint Web Part Properties

While SharePoint's User Defined Site Template saves you work by allowing users to tweak their interface designs themselves, allowing them to save site templates creates work for you. If you want to tip the workload balance back in your favor, a little Reflection can go a long way.

harePoint's User Defined Site Template helps empower your end users to take control of their own user interface design, pushing much of the user interface design responsibility away from traditional developers.

Once your users are done tweaking the look and feel of a given interface, they can save the design as a template. The templates are stored in the Site Template Collection list, located at the root site of the current site collection. For example, if your site URL is http://server/sites/rootsite/site1/site2 and you save it as a template, the template will be located in the http://server/sites/rootsite Site Template Collection.

Figure 1. The Site Creation Wizard: The image shows template availability during site creation.

These templates are available during a site's creation process, from any level within the site collection tree (the root site and all its sub-sites). Figure 1 shows the template's availability during the site creation wizard. Your users now have the ability to replicate their site many times over, all without needing any assistance from you.

However, because all their properties are set at design time, creating sites based on these saved site templates results in static content. This can become a problem in today's business environment, which demands dynamic site content.

Enter Reflection
.NET brought with it a set of tools neatly grouped into the System.Reflection namespace, which solves this problem. Reflection allows you to query information from any assembly—even the same assembly—dynamically. Information such as properties, fields, and methods, which were declared as public in the assembly, can be reflected. In addition, reflection allows you to retrieve the values of these properties and/or fields as well as set those values dynamically. Reflection also allows you to dynamically invoke methods of the assembly at run time and dynamically compile the code. With it, you can dynamically set a template's Web part properties, thus rendering a static site dynamic.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date