Presentation is loading. Please wait.

Presentation is loading. Please wait.

SharePoint Word automation SERVICES

Similar presentations


Presentation on theme: "SharePoint Word automation SERVICES"— Presentation transcript:

1 SharePoint Word automation SERVICES

2 Typical word Conversion scenario
Typical Scenario User request: Please convert 10,000 word documents to PDF by the end of the week. Developer: Time for Ole automation to open the Word document and save the word document as a PDF. Developer After running for 1 Day only 400 document were converted because we ran out of memory! Time for plan B, Adobe distiller or third party. Problem solved! User request I have more documents and I would like users to pick and choose which files they should convert NOOOOOOOOOOOOOOOO!

3 Word automation services to the recuse
What is Word Automation Services? Word Services is functionality in SharePoint 2010 that allows developers to transform Word documents into other document types like PDF, XPS, and other formats Also file operation can be executed on the file without having to open it in a client application Regular Word document types can be converted into different document types OpenXML can be utilized to perform insert, append, update, and delete operations on content within the documents

4 Right on time! The service runs as a timer job so this allows for the service to take full advantage of the environment Reliability Timer job can run of different machine so if one machine is down another one can take it place Scalability One a farm with adequate size the service can execute jobs on multiple servers distributing the work load Speed In most Production environments the hardware is sized to run thousands or millions of instructions and processes License SharePoint Server 2010 is for standard and enterprise CAL

5 What’s needed? Nothing BUT SHAREPOINT 2010 and a little code Now solutions can be given to the user without deploying code to their desktop! Word Services OpenXML SDK 2.0

6 User’s problem/Our solution
Problem: User’s want to selectively pick word documents and convert them to different formats like PDF or XPS. Solution: Within a document library allow users to select which documents they want to convert. Utilize the ribbon, it’s a great pluggable interface that can be easily be extended. On the ribbon we will give the user a drop down of document types and two buttons quick and batch convert. Also for our power users sanity provide a third button called Check Status. Use a document library’s ribbon Put controls in ribbon using a custom action Provide a status page

7 File formats the service can…
Read: Office Open XML (DOCX, DOCM, DOTX, DOTM) Word Document (DOC) and Word Template (DOT) We also support older versions of Word as far back as Word 2.0 for Windows (!) Rich Text Format (RTF) Single File Web Page (MHTML) HTML Word 2003 XML Word 2007/2010 XML Write: PDF XPS Office Open XML (DOCX, DOCM) Word Document (DOC)

8 Word services architecture
Object Model The object model resides on a SharePoint Server 2010 Web front-end server; it enables developers to create asynchronous file conversion requests and to monitor file conversions in progress. Document Queue The document queue manager resides on a back-end application server; it moves incoming requests into the document queue database and sends requests to the Word Automation Services engine for processing. A timer job controls the frequency of conversions and the number of files that are actively being converted Word Automation Services Engine The Word Automation Services engine provides an optimized, server-based rendering engine that can use server features, such as the availability of multiple processors. In multiple-server configurations, the Word Automation Services engine balances the load to ensure that no single application server is overloaded by conversion requests. Resource from

9 environment Virtual Machine (4 GB RAM) Windows 7 x64
Visual Studio 2010 x32 ( no x64 yet) SharePoint 2010 Software Solution Empty SharePoint Project Add an element file - Ribbon Add Application pages – Pages to submit the jobs Add a JavaScript external file – Client side JS to talk to the

10 Solution SEQUENCE

11 solution - Ribbon Ribbon <CustomAction Id ="CushWake.WordConversion.Ribbon.Scripts" Location="ScriptLink" ScriptSrc="/_layouts/CushWake/WordConversion/ConversionScript.js" /> <CustomAction Id="CushWake.WordConversion.Ribbon" Location="CommandUI.Ribbon" RegistrationId="101" RegistrationType="List" Title="Word Conversion"> <Tab Id="CushWake.WordConversion.Ribbon.Tab" Title="Word Conversion" Sequence="501"> <MenuSection Id="CushWake.WordConversion.ConversionGroup.Section.Quick" Sequence="10" DisplayMode="Menu32"> <Controls Id="CushWake.WordConversion.ConversionGroup.Controls.Quick"> <Button Id="CushWake.WordConversion.ConversionGroup.Button.Quick.PDF" Command="WordConversionButtonCommand.ConversionQuick.PDF" Image32by32="/_layouts/images/CushWake/WordConversion/clock32.png" LabelText="PDF" Sequence="10" TemplateAlias="cust1" /> <CommandUIHandlers> <CommandUIHandler Command="WordConversionButtonCommand.JobStatus" CommandAction="/_layouts/CushWake/WordConversion/ConversionJobs.aspx?listId={ListId}" /> <CommandUIHandler Command="WordConversionButtonCommand.ConversionQuick.PDF" CommandAction="javascript:quickConvert('PDF');" EnabledScript="javascript:isItemSelected();" /> <CommandUIHandler Command="WordConversionButtonCommand.ConversionQuick.DOCM" CommandAction="javascript:quickConvert('DOCM');" EnabledScript="javascript:isItemSelected();" /> <CommandUIHandler Command="WordConversionButtonCommand.ConversionQuick.DOTX" CommandAction="javascript:quickConvert('DOTX');" EnabledScript="javascript:isItemSelected();" /> Be very careful the slightest mistake will have you trying to debug for hours or days! Custom Action for adding external references to JavaScript libraries Custom Action for add menu items

12 Solution - Javascript Asynchronous Call function quickConvert(cfmt) { var ctx = SP.ClientContext.get_current(); var myItems = buildDeliminatedKeys(); var listGuid = SP.ListOperation.Selection.getSelectedList(ctx); var url = '/_layouts/XYZ/WordConversion/quickConversion.aspx?cfmt=' + cfmt + '&items=' + myItems + '&listId='+listGuid; var req = new Sys.Net.WebRequest(); req.set_url(url); req.set_httpVerb("POST"); req.add_completed(OnRequestCompleted); req.invoke(); } SharePoint Dialog Box function convert() { var ctx = SP.ClientContext.get_current(); var listGuid = SP.ListOperation.Selection.getSelectedList(ctx); var myItems = buildDeliminatedKeys(); var options = { url: '/_layouts/XYZ/WordConversion/Conversion.aspx?items=' + myItems + '&listId='+listGuid, tite: 'Document Batch Convert', allowMaximize: false, showClose: false, width: 700, height: 400, dialogReturnValueCallback: updateScreenCallback }; SP.UI.ModalDialog.showModalDialog(options);

13 Solution-calling the Word service
public static ConversionJob CreateJob(SPUserToken userToken,SaveFormat fmt,string jobTitle) { ConversionJob job = new ConversionJob("Word Automation Services"); job.UserToken = userToken; job.Settings.UpdateFields = true; job.Settings.OutputFormat = fmt; job.Name = jobTitle; return job; } job.AddFile(SPContext.Current.Site.MakeFullUrl(spiDoc.Url), destFile); Job.Start(); Other methods job.AddFolder Job. AddLibrary

14 SOLUTION-Monitoring ReadOnlyCollection<ConversionJobInfo> conversionJobs = ConversionJobStatus.GetAllJobs("Word Automation Services", null); var cJob = (from job in conversionJobs orderby job.SubmittedTime descending select job); Guid jobGuid = new Guid(jobGuidString); ConversionJobStatus jobStatus = new ConversionJobStatus("Word Automation Services", jobGuid, null); lblFailed.Text = jobStatus.Failed.ToString(); lblJobCount.Text = jobStatus.Count.ToString(); lblSucceeded.Text = jobStatus.Succeeded.ToString(); lblInProgress.Text = jobStatus.InProgress.ToString();

15 SOLUTION-Monitoring cont’d
JobInfo.JobItemTableDataTable jobItemTable = new JobInfo.JobItemTableDataTable(); List<ItemTypes> jobItemTypes = new List<ItemTypes>() {ItemTypes.Succeeded, ItemTypes.Canceled,ItemTypes.Failed,ItemTypes.InProgress,ItemTypes.NotStarted }; string inputFile, outputFile; bool isJobUrlSet=false; string srcUrl=String.Empty, destUrl=string.Empty; foreach (ItemTypes itemType in jobItemTypes) { foreach (ConversionItemInfo item in jobStatus.GetItems(itemType)) inputFile = item.InputFile.Substring(item.InputFile.LastIndexOf("/")+1); outputFile = item.OutputFile.Substring(item.OutputFile.LastIndexOf("/")+1); jobItemTable.AddJobItemTableRow(inputFile, outputFile, item.ErrorMessage, item.StartTime.ToString(), item.CompleteTime.ToString(), itemType.ToString());

16 Word automation services - settings

17 Resources Word Automation Services Architecture
Open XML SDK 2.0 for Microsoft Office Setting Up the Development Environment for SharePoint 2010 on Windows Vista, Windows 7

18 Issue, resolution,& Guidelines
Word Automation Services has to be explicitly enabled. Using OpenXml had trouble finding System.IO.Packing for .Net 4.0 add the WindowsBase to your project Word Automation Service Settings Worker processes = #CPU – 1 Max of 90 documents per worker process per minute Invalid document have a high memory cost All memory is reclaim when the process is restarted You can set the # of times to try to convert the document


Download ppt "SharePoint Word automation SERVICES"

Similar presentations


Ads by Google