Word Automation Services: Determining Which Documents Failed to Convert using VB
This is the complete sample for determining which documents failed to convert from the article Developing with SharePoint 2010 Word Automation Services.
This blog is inactive.
New blog: EricWhite.com/blog
Imports System.Collections.ObjectModel
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 = "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)
Dim failedItems As ReadOnlyCollection(Of ConversionItemInfo) = _
status.GetItems(ItemTypes.Failed)
For Each failedItem In failedItems
Console.WriteLine("Failed item: Name:{0}", failedItem.InputFile)
Next
Exit While
End If
Console.WriteLine("In progress, Successful: {0}, Failed: {1}", _
status.Succeeded, status.Failed)
End While
End Using
End Sub
End Module