SharePoint 2010 Word自动化服务和事件接收器

时间:2017-09-29 06:53:21

标签: c# ms-word sharepoint-2010 pdf-generation eventreceiver

我正在使用SharePoint 2010事件接收器。我在特定列表上运行此事件接收器,在某些条件下,我在库中创建word文档的副本,并使用动态值编辑其属性,然后使用word自动化服务将此文档转换为同一库中的PDF。

我的word文档是在word文档中插入所需的文档属性而正确创建的。代码正确执行,但文档未转换为PDF。

以下是转换代码:

using (SPSite spSite = new SPSite("http://MySharePoint Site"))
            {

                SPServiceContext serviceContext = SPServiceContext.GetContext(spSite.WebApplication.ServiceApplicationProxyGroup, SPSiteSubscriptionIdentifier.Default);

                var wordAutomationProxy = (WordServiceApplicationProxy)serviceContext.GetDefaultProxy(typeof(WordServiceApplicationProxy));

                //Defines a collection of settings for all conversions within a single conversion job.
                ConversionJobSettings jobSettings = new ConversionJobSettings();
                jobSettings.OutputFormat = SaveFormat.PDF;
                //Represents a collection of file conversions (of single files or entire libraries) that share a common set of conversion properties and are logically tracked as a single unit.
                ConversionJob pdfConversion = new ConversionJob(wordAutomationProxy, jobSettings);
              // Set the credentials to use when running the conversion job.
                pdfConversion.UserToken = spSite.UserToken;                    
                pdfConversion.AddFile(DocFilePath, PDFFilePath);
                pdfConversion.Start();

}

1 个答案:

答案 0 :(得分:0)

我重新创建了自动化服务这个词,解决了我的问题。没有代码更改。