How to force the Word Automation Services Timer to run?
-
06-12-2019 - |
Question
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 ?
Solution
I used reflection to force the Automation Services to execute immediately. Works fine in our environment :-) http://devtopics.de/2013/11/18/making-sharepoint-2010-and-word-automation-services-convert-to-pdf-immediately-for-real/
OTHER TIPS
Try setting the schedule for the timer job to DateTime.Now, and update the job definition. Should execute it immediately that way.
jobDefinition.Schedule.NextOccurrence(DateTime.Now);
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange