kevin
kevin

Reputation: 14075

Pass parameter to SharePoint Timer job

How can I pass a parameter to a SharePoint Timer job?

btw, I am just a beginner to SharePoint.

Thanks.

UPDATE

I am moving documents from one site to another site according to external DB status. So I want to pass those DB user name and password, SharePoint sites' names as parameter. I don't wanna hardcode those.

Upvotes: 2

Views: 5138

Answers (3)

Raheel
Raheel

Reputation: 570

you can store your userid and psw in config file i.e. OWSTIMER.EXE.CONFIG. you can find this file at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN. if it is not their then you can create one. please make sure that file name must be in capital leters. below i have mentioned sample content of this config file.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <appSettings>
      <add key="USERID" value="testUser" />
      <add key="PSW" value="testPSW" />
    </appSettings>
</configuration>

if you are using C# then you can access these nodes using

System.Configuration.ConfigurationManager.AppSettings["USERID"]
System.Configuration.ConfigurationManager.AppSettings["PSW"]

Dont forget to reset your sharepoint timer service once you made changes in your config file.

Upvotes: 1

Koen van der Linden
Koen van der Linden

Reputation: 833

You could use the SPWorkItemJobDefinition

You can use TextPayload to pass parameters (document url, fromSiteUrl, toSiteUrl etc.)

It's like using a queue. Pass in some parameters from UI. Timerjobs processes queue, reads the payload and starts processing.

Upvotes: 3

Tschareck
Tschareck

Reputation: 4239

When you write your timer job, you will override Execute(Guid targetInstanceId) method from the SPJobDefinition. Here you cannot unfortunately pass any parameters.

What you can do, is to store the values somewhere, where your timer job would be able to access them. One way, as this question mentions, would be to put that in a .config file inside of 14 Hive. Or some database table. Or SPPropertyBag in your SPWeb.

Upvotes: 2

Related Questions