如何以编程方式执行Word Automation Services?

时间:2011-05-02 18:21:12

标签: c# asp.net sharepoint sharepoint-2010 word-automation

如何以编程方式强制执行/启动Word Automation Services? 我需要在提交转换过程后启动/执行。

    string siteUrl = "http://localhost";
    string wordAutomationServiceName = "Word Automation Services";
    using (SPSite spSite = new SPSite(siteUrl))
    {
        ConversionJob job = new ConversionJob(wordAutomationServiceName);
        job.UserToken = spSite.UserToken;
        job.Settings.UpdateFields = true;
        job.Settings.OutputFormat = SaveFormat.PDF;
        job.AddFile(siteUrl + "/Shared%20Documents/Test.docx", siteUrl + "/Shared%20Documents/Test.pdf");
        job.Start();
    }

2 个答案:

答案 0 :(得分:4)

是的,您可以强制作业立即从代码和中央管理界面启动。请参阅我的解决方案(构建于 SPJobDefinition 类的 RunNow 方法之上)here

您应该启动 Word Automation Services计时器作业

对于eaxmple,使用PowerShell:

$watj = Get-SPTimerJob "Word Automation Service Application"
$watj.RunNow()

甚至更短:

Start-SPTimerJob "Word Automation Services"

答案 1 :(得分:2)

您是否在询问是否有办法强制立即执行作业,而不是等待Word自动化服务管理设置中设置的时间间隔? 目前,在Word 2010的Word Automation Services中,无法执行此操作。我能想到的是将时间间隔改为最少1分钟(而不是默认的15分钟)。