SharePoint 2010 WAS ConversionJob
Use the Word Automation Services ConversionJob object to bulk convert documents, for example DOCX to PDF, and monitor the job.
Word Automation Services (WAS) converts files in bulk from one format to another. It works asynchronously, so it puts little load on the application server.
Supported formats
WAS can read:
- Office Open XML (DOCX, DOCM, DOTX, DOTM)
- Word 97-2003 Document (DOC) and Word 97-2003 Template (DOT)
- Rich Text Format (RTF)
- Single File Web Page (MHTML)
- HTML
- Word 2003 XML
- Word 2007/2010 XML
WAS can write:
- XPS
- Office Open XML (DOCX, DOCM)
- Word 97-2003 Document (DOC)
- Rich Text Format (RTF)
- Single File Web Page (MHTML)
- Word 2007/2010 XML
Creating a job
Create a job with the ConversionJob managed API object.
csharp
ConversionJob job = new ConversionJob("Word Automation Services");
job.UserToken = SPContext.Site.UserToken;
job.UpdateFields = true;
job.OutputFormat = SaveFormat.PDF;
job.AddFile("http://mysite/doclib/doc.docx", "http://mysite/pdflib/pdf.pdf");
job.Start();
Monitoring a job
Check progress with the ConversionJobStatus object.
csharp
ConversionJobStatus status = new ConversionJobStatus("Word Automation Services",
job.JobId, null);
if (status.Count == status.Succeeded)
{
//Handle success
}
else if (status.Count == status.Failed)
{
//Handle failure
}