Access web.config from SharePoint Timer Job

While working on a public facing website using MOSS 2007 I needed to created an XML sitemap to be used by Google and other search engines. I looked around at various different options but eventually found a Blog article by Tim Dobrinski. This covered most of my requirements, however there were a few things I wanted to parameterise such as a list of sites to be excluded from the XML and also the document library the XML file was to be uploaded to.

Talking to a colleague, Gordon Duthie, he mentioned he had done something similar and blogged about it. After reading his blog, Reading from web.config’s AppSettings in a SharePoint timer job, I thought this would be nice and easy. The complication arose from the fact the client had a web application they were using to edit the content for the site and then this was extended and given the public facing site URL.

When I started to use the code it seemed to be working correctly but then I added a setting in the web application web.config and the extended web.config with different values. I found it was only ever hitting the original web.config. Thinking about it this made perfect sense as while there are two sites in IIS there is only one web application. Even though I am accessing the site via the extended application URL the web application name, which is what my colleague was using to get the path to the web.config, was always going to be the actual web application name and not the name of the extended web application.

There may be other workarounds but I decided I would use a custom property to pass information to the timer job, adding properties to a custom SharePoint Timer Job. The only down side of this is if I need to change the details being passed to the timer job I have to deactivate and then reactivate the feature.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: