Friday, November 27, 2009

Using configurations in MOSS Web Parts/ InfoPath browser forms

There are times when we want some values to be configurable. For example, a hyperlink in MOSS web part or an InfoPath browser form must be configurable so that when the artifacts are moved across environments, the link points to correct target.

This can be achieved in simple web.config changes of MOSS web application as follows:
Step 1:
Define a sectiongroup tag under

<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
</sectionGroup>

Step 2:
Add a corresponding .Settings tag under applicationSettings group we defined

<section name="SampleConfig.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />


Step 3:

Now that we have defined a placeholder, we can define actual configuration settings under it.
<applicationSettings>
<SampleConfig.Properties.Settings>

<setting name="AHyperLink" serializeAs="String">
<value>http://abc</value>
</setting>
</
SampleConfig.Properties.Settings>
</applicationSettings>

Why this works?
Thanks to the ASP.NET infrastructure upon which MOSS is built. The MOSS web application undergoes the same ASP.NET request processing pipeline. Hence, the configurations defined above work. Please note that the highlighted tag names must match for this to work.

No comments: