Recently I needed to create a persist-able copy of a SharePoint Calendar list from web application A to web application B in the same SharePoint farm. Since I really needed the copy, not just querying, I had 2 options:
1. Event receivers on the calendar list in source web application. But this has one big drawback – application pool account for source web application must have write access to destination web application. Big Infrastructure guys would not like that in my case…
2. Farm-scoped timer job. This is perfect from infrastructure point of view, but I was puzzled with how to specify the actual source and destination URLs to the timer job?
…At first I created 2 SPWeb-scoped features, “Source TJ Anchor” and “Destination TJ Anchor” and activated them on the needed webs. What those features did is just added some identifying information to SPWeb.AllProperties property bags. Then, timer job would run and iterate literally through everything and after finding the needed SPWeb objects stored their URLs in [Persisted] variables, to use them in later iterations.
That’s fine. But a colleague then suggested a ways more elegant solution – to create an application page in the central administration and to put link to it near the timer job settings section! Easy as that!
The values in the page are stored, again, in the AllProperties property bag of the root web of Central Administration web application.
A VERY EASY non-hardcode WAY to access such root web is this:
Microsoft.SharePoint.Administration.SPAdministrationWebApplication webAppCA = SPAdministrationWebApplication.Local;
// Since webAppCA is a web application just access it’s first site collection’s RootWeb
SPweb rootWeb = webAppCA.Sites.RootWeb;
Page is added via Elements.xml file in a Module element inside your Visual Studio solution:
<?xml version=“1.0” encoding=“utf-8”?>
<CustomAction Id=“0C1114DD-E4AB-4C53-AD48-4D395DB1BB21” GroupId=“TimerJobs”
Title=“UTU Calendar Synchronization” Description=“”>
<UrlAction Url=“_admin/UTUCalSync.aspx” />
NOTICE!! When adding your ASPX application page to the project make sure it is deployed to the ADMIN mapped SharePoint folder instead of LAYOUTS! This will indicate that this page is intended for use in Central Administration web application.