Lets explore Word Automation Service

The great feature introduce in SharePoint 2010 .Do you want to convert one file format to another ,this is right place .You can use it to convert a .doc or .docx document into an .xps or .pdf file.

The following list shows the supported input formats:

  • Open XML File Format documents (.docx, .docm, .dotx, .dotm)
  • Word 97-2003 documents (.doc, .dot)
  • Rich Text Format files (.rtf)
  • Webpages (.htm, .html, .mht, .mhtml)
  • Word 2003 XML Documents (.xml)
  • Rich Text Format files (.rtf)
  • Webpages (.htm, .html, .mht, .mhtml)
  • Word 2003 XML Documents (.xml)
  • Portable Document Format (.pdf)
  • Open XML Paper Specification (.xps)

Lets see example of converts a document from .DOC to .XPS by using the Server Object Model of the Word Automation Services

Sample Code:

SPFile sourceFile = web.GetFile(“Shared%20Documents/Source.doc”);
ConversionJob job = new ConversionJob(wordAutomationServiceName);
job.UserToken = site.UserToken;
job.Settings.UpdateFields = true;
job.Settings.OutputFormat = SaveFormat.XPS;

String sourceUrl = web.Url + “/” + sourceFile.Url;
String destinationUrl = web.Url + “/” +
sourceFile.Url.Replace(“.doc”, “.xps”);
job.AddFile(sourceUrl, destinationUrl);
job.Start();

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s