Friday, January 27, 2012

SharePoint : How to run Code on All Web Servers -A Timer Job or multi-server jobs

How to run Code on All Web Servers (All WFE for instance) : A Timer Job or multi-server jobs:




To define a timer job

  1. In Visual Studio, start an Empty SharePoint Project. Make it a farm solution, not a sandboxed solution.
  2. Highlight the project name in Solution Explorer and be sure that Include Assembly in Package in the Properties pane is set to true.
  3. Add a C# or Visual Basic class file to the project.
  4. Open the class file and add using statements (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Administration namespaces. You may need to add other using statements depending on what namespaces are called by the code that you want to execute on all servers. For the running example in this topic, add using statements for System.Xml.Linq, System.Xml.XPath, System.IO, and System.Runtime.InteropServices.
  5. Change the namespace to conform to the guidelines in Namespace Naming Guidelines; for example, Contoso.SharePoint.Administration.
  6. Change the class declaration to specify that the class inherits from SPJobDefinition or from some class that derives from SPJobDefinition.
  7. Decorate the class declaration with a GuidAttribute attribute. This is a requirement for any class that derives directly or indirectly from SPPersistedObject.
  8. Add a default (parameterless) constructor to the class that simply calls the base constructor.
  9. Add a constructor with parameters of types String, SPWebApplication, SPServer, and SPJobLockType. Its implementation should call the base constructor SPJobDefinition(String, SPWebApplication, SPServer, SPJobLockType). The following shows what your code should look like in C# at this point.
...Read on...

    No comments:

    Post a Comment