Create a custom timer job to gather data and generate report source files

If you want to generate your own custom reports, you can build a custom timer job that gather information about SharePoint (or any system that you can query from your SharePoint servers). Data is saved as an XML file stored into the "Reports (SoV)" document library that is in the "Reports Center". This XML can be of any structure you want, just been valid in term of XML formatting.

SharePoint Of View - SPReporting is a Framework and already contains a base timer job to help you build your own, and also a Feature Receiver to install it easily.
Here are the steps to achieve it.

This sample can be downloaded from the "Release" section (find the file).

I. Create a Visual Studio project

We use Visual Studio 2008 in this tutorial, but you can use Visual Studio 2005 the same way.

First, open Visual Studio and create a project using the "Class Library" template. You may select Framework 2.0 or 3.0 if you don't want to require Fx .Net 3.5 installation on the SharePoint servers.

Create a VS project

Then add a reference to the SharePointOfView.SPReporting.dll

Add reference

TIP: you can get it from the SharePointOfView.SPReporting.wsp solution file by renaming it with the ".cab" extension, browsing it and extracting the DLL.

Add also a reference to the Microsoft.SharePoint.dll to use the SharePoint API. You should get that :


You can delete the "Class1.cs" file.

II. Create the job

Now add a new class file (called here "MyJob.cs" for instance).

New class file

Add the following "using" statements :

  • Microsoft.SharePoint and Microsoft.SharePoint.Administration to use and access SharePoint
  • SharePointOfView.SPReporting.Jobs to inherit base classes and use helpers
  • System.Xml to generate the XmlDocument object returned to the base class

The class must inherit from SharePointOfView.SPReporting.Job.GenericJobDefinition and implement the following two constructors (both are mandatory : empty constructor and specific one).


Implement the virtual method "GatherData()", here is a sample that lists all feature definitions.


Don't forget to sign your assembly as it must be deployed in the Global Assembly Cache.

Signing your assembly

Next articles :
  • Use the sortable datetime pattern (ISO 8601 : yyyy-MM-ddTHH:mm:ss) for any datetime values in XML (DateTimeVariable.ToString("s"))
  • Try to use the old .Net XML API (XmlDocument & co) instead of LINQtoXML to avoid the Framework .Net 3.5 pre requisite on servers
  • If you update the code of your job and redeploy it, don't forget to restart the "Windows SharePoint Services Timer" service with these two commands : "net stop sptimerv3" then "net start sptimerv3".

Last edited Dec 28, 2008 at 10:46 PM by GatWeb, version 9


No comments yet.