次の方法で共有


Word Automation Services: Monitoring Status of Conversion Jobs using VB

This is the complete sample for monitoring the status of conversion jobs from the article Developing with SharePoint 2010 Word Automation Services.

This blog is inactive.
New blog: EricWhite.com/blog

Blog TOC

Imports System.Threading
Imports Microsoft.SharePoint
Imports Microsoft.Office.Word.Server.Conversions
Module Module1
    Sub Main()
        Dim siteUrl As String = "https://localhost"
        ' If you manually installed Word Automation Services, then replace the name
        ' in the following line with the name that you assigned to the service when
        ' you installed it.
        Dim wordAutomationServiceName As String = "Word Automation Services"
        Using spSite As SPSite = New SPSite(siteUrl)
            Console.WriteLine("Starting conversion job")
            Dim job As ConversionJob = New ConversionJob(wordAutomationServiceName)
            job.UserToken = spSite.UserToken
            job.Settings.UpdateFields = True
            job.Settings.OutputFormat = SaveFormat.PDF
            job.Settings.OutputSaveBehavior = SaveBehavior.AlwaysOverwrite
            Dim listToConvert As SPList = spSite.RootWeb.Lists("Shared Documents")
            job.AddLibrary(listToConvert, listToConvert)
            job.Start()
            Console.WriteLine("Conversion job started")
            Dim status As ConversionJobStatus = _
                New ConversionJobStatus(wordAutomationServiceName, job.JobId, Nothing)
            Console.WriteLine("Number of documents in conversion job: {0}", status.Count)
            While True
                Thread.Sleep(5000)
                status = New ConversionJobStatus(wordAutomationServiceName, job.JobId, _
                                                 Nothing)
                If status.Count = status.Succeeded + status.Failed Then
                    Console.WriteLine("Completed, Successful: {0}, Failed: {1}", _
                                      status.Succeeded, status.Failed)
                    Exit While
                End If
                Console.WriteLine("In progress, Successful: {0}, Failed: {1}", _
                                  status.Succeeded, status.Failed)
            End While
        End Using
    End Sub
End Module