You can use your favorite social network to register or link an existing account:
Or use your email address to register without a social network:
Sign in with these social networks:
Or enter your username and password
Forgot your password?
Yes, please link my existing account with for quick, secure access.
No, I would like to create a new account with my profile information.
Tips
How-to
News
Videos
Stories
In the Word Automation Services: What It Does post, I provided a very high-level outline of the server-side API provided by the service, showing you the basic outline for working with the service:
In this post, I wanted to look at a specific example solution and what's involved in creating it, to walk through a real example of the service end-to-end.
In this example, I have a library in which I store contracts as they're being written. Once they're approved, I set the Status property for that document within the library to "Final" and an XPS version of it is automatically generated to archive the agreed-upon version of the content.
I've written up the solution in tutorial form, so folks w/ Visual Studio 2010 and SharePoint 2010 can actually build the resulting workflow; if that's not your goal, browsing the sample code should be enough to give you an idea of how the solution works.
Before we start, we add the Status column to the Document content type, so that we can use it in this walkthrough.
First, we create a SharePoint project in Visual Studio which will contain our workflow code.
At this stage, we now have a new empty workflow project.
To perform conversions, we need to include a reference to the Word Automation Services object model.
Note: If you receive a warning that the DLL requires a newer version of the .NET Framework, choose Yes to add the reference anyway. Then, add a reference to System.Web.DataVisualization, typically located at C:\windows\Assembly\GAC_MSIL\System.Web.DataVisualization\3.5.0.0__31bf3856ad364e35\.
Now that we have a workflow project, we will add a two-step workflow: the first step checks whether the Status property has been set to "Final"; once it has, the second step converts the document.
This tells the activity the information necessary to associate the ItemChanged event with the correct workflow.
bool documentReady = false;
//check if the Status is set to final; if so, the document is ready to archive if (workflowProperties.Item["Status"] != null) { _documentReady = ((string)workflowProperties.Item["Status"] == "Final"); }
documentReady == false
The resulting workflow now looks like:
Now that we've created the portion of the workflow that waits for the column value to be set to Final, we add the workflow activity to actually convert the document.
//create a conversion jobConversionJob job = new ConversionJob("Word Automation Services");
//specify conversion settings job.UserToken = workflowProperties.OriginatorUser.UserToken; if (workflowProperties.Site.SiteSubscription != null) job.SubscriptionId = workflowProperties.Site.SiteSubscription.Id; job.Settings.OutputFormat = SaveFormat.XPS; job.Name = "Archive Document Workflow";
//add the file string fileUrl = workflowProperties.WebUrl + "/" + workflowProperties.ItemUrl; job.AddFile(fileUrl, Path.ChangeExtension(fileUrl, "xps"));
//schedule the conversion job.Start();
This code creates a new ConversionJob, which defines a set of conversions, supplying the name of the service application. Note: This example assumes the name of the service application is "Word Automation Services", which is the default name when it is created via the Farm Configuration Wizard. If you have used a different name for the service application, change the name as appropriate.
Then, we set the necessary settings for the conversion:
As well, we specify one optional setting:
Next, we add the file to the conversion job via the AddFile method, and start the processing of the conversion using the Start method.
Once we've scheduled the conversion, it is processed asynchronously. Finally, we can add a step to monitor the result of the conversion before terminating the workflow, so that the workflow completes after the conversion.
Guid jobId; bool conversionComplete = false;
//save the job's ID jobId = job.JobId;
//monitor the conversion //get the site subscription ID Guid? siteSubscription = null; if (workflowProperties.Site.SiteSubscription != null) siteSubscription = workflowProperties.Site.SiteSubscription.Id;
//check if the conversion is complete; if it is, refresh ConversionJobStatus status = new ConversionJobStatus("Word Automation Services", jobId, siteSubscription); if (status.Count == status.Succeeded) { //success! conversionComplete = true; } else if (status.Count == status.Failed) { //conversion failed ReadOnlyCollection<ConversionItemInfo> failedItems = status.GetItems(ItemTypes.Failed); throw new Exception(failedItems[0].ErrorMessage); } else if (status.Count == status.Canceled) { //conversion was canceled throw new Exception("Conversion was canceled."); }
//since we didn't finish, keep waiting
This code checks the status of the conversion using the ConversionJobStatus object. Note: This example assumes the name of the service application is "Word Automation Services", which is the default name when it is created via the Farm Configuration Wizard. If you have used a different name for the service application, change the name as appropriate.
Once we have the status for the job, we can check whether the item has succeeded or failed, and react accordingly. Otherwise, we do nothing, since the conversion is still in progress.
conversionComplete == false
The final workflow should look like this:
Now, deploy the solution to your SharePoint farm.
When the timer job runs and the conversion is processed, you should see the XPS file appear next to the original document (refresh the page to see the result). Note: Again, because the conversions are processed using a timer job, it may take up to the frequency of the timer job for the file to appear.
Comments: (5) Collapse
Will a set of WF-activities be supplied for Word Automation Services? Since Code-activities are no longer possible (kind of) in WF4, a future migration is probably required, while it would not be if a standard activity would be supplied (and in the future a WF4-version).
אני צריכה את זה בשביל משימות שנותנים לי מהבית ספר ובשביך להדפיס דרך זה עבודות
Sorry this is offtopic and unrelated to the blog post (as the Word team blog has no "Email" link like other Office blogs) but will there be a Word 2010 Viewer and when will it be available?
Hi "Word User" - There won't be a new Word 2010 Viewer, and Word 2010 files can be viewed for free in the existing client and new web viewer. - Joanthan Bailor (MS)
Why are letters so small?
Comments: (loading) Collapse