Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I need to run the Word Automation Services immediately after adding a job. My code is running in a workflow.

Here is what I got so far :

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    using (SPSite spSite = new SPSite(site))
    {
        var job = new ConversionJob("Word Automation Services");
        job.UserToken = spSite.UserToken;
        job.Settings.UpdateFields = false;
        job.Settings.OutputFormat = SaveFormat.PDF;
        job.AddFile(source, destination);
        job.Start();

        foreach (var service in spSite.WebApplication.Farm.Services)
        {
            if (service.TypeName == "Word Automation Services")
            {
                foreach (var jobDefinition in service.JobDefinitions)
                {
                    if (jobDefinition.Name == "Word Automation Services")
                    {
                        jobDefinition.RunNow();
                        break;
                    }
                }
            }
        }
    }
});

But I got an access denied on the RunNow() method. Is there a way to call this method from a workflow ?

share|improve this question
add comment

2 Answers

Try setting the schedule for the timer job to DateTime.Now, and update the job definition. Should execute it immediately that way.

share|improve this answer
    
Can you give a sample code for what you say ? I didn't found a way to translate what you said in code. –  Baptiste Wicht Dec 26 '11 at 12:18
add comment

jobDefinition.Schedule.NextOccurrence(DateTime.Now);

share|improve this answer
    
While this may theoretically answer the question, it is more helpful if you can provide a bit more information than just a fragment of code. Thanks. –  SPDoctor Feb 8 '12 at 12:09
    
I tried your solution, but it didn't change anything. –  Baptiste Wicht Feb 8 '12 at 18:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.