To give you an idea of how OpenXML and Word Automation Services can be used together to build useful line-of-business applications, consider the following demonstration scenario: You’ve been engaged by AdventureWorks to design and build a document creation and collaboration tool. The tool will be used by the company’s sales department for producing sales proposals. Each proposal is made up of a number of different documents contributed by various users from different departments. The tool to be built should combine these documents into a single read-only document that can be sent to the customer for consideration. The input documents will be saved in Microsoft Word OpenXML format. The output document should be in Adobe Acrobat (PDF) format.
You need to consider the following points to create an architecture that fits this scenario:
Creating a Custom Content Type
First we’ll create a new bank site and then provision the Document Set content type before we add a custom content type and define our user interface.
Customizing the DocumentSetProperties Web Part
Before we can customize the welcome page for our custom document set, we need to build a web part with the following additional features:
Although we could create a separate web part that could be used in conjunction with the built-in DocumentPropertiesWebPart, it wouldn’t be overly useful as a stand-alone component elsewhere. Instead, we’ll create a web part that inherits from the DocumentPropertiesWebPart and adds our required additional functionality.
TIPWhen overriding any built-in SharePoint classes, it can be challenging to work out exactly what you need to do to get the behavior that you expect. In the code snippet, to get our web part to render properly, we explicitly need to render our custom user control by overriding RenderWebPart method. Uncovering details such as this from the documentation is often impossible. With our custom user control properly hooked up to our web part, we can implement the rest of our custom logic via the user control.
Before our customized web part can be deployed,we need to make a few changes to the solution. The default packaging mechanisms that are set up in Visual Studio work well for creating web parts that are derived directly from System. Web. UI. Web Controls.Webparts. Webpart. However, when creating a web part that’s derived from another base class, we’ll occasionally see an “Incompatible Web Part Markup” error message when we’re trying to use the deployed web part on a page. To resolve this error, we need to use an alternative packaging format.
Creating a Custom Job Definition
With our user interface largely complete, our next step is to define a custom job that will compile all documents in our document set and send the compiled output to Word Automation Services for conversion to PDF. In Visual Studio, add a new class named DocumentCombinerJob.cs. Add the following code to the file:
Developers familiar with SharePoint 2007 should notice a few interesting elements in this code snippet. First, check out the HasAdditionalUpdateAccess override. In previous versions of SharePoint, only farm administrators could create jobs. This greatly restricted their usefulness for offloading ad hoc tasks. With SharePoint 2010, where the HasAdditionalUpdateAccess method returns true, any user can create a job. Also notice that when we’re creating a job, the job can be associated with either a service or an application pool. These associations are primarily for administrative purposes since most jobs run via the SPTimerV4 service. In our example, we’re associating our custom jobwith the TimerService. The final thing to notice is that job definitions are serialized when a job is created. As a result, not all types of objects can be defined as properties. For example, the SPListItem isn’t serializable and therefore can’t be stored as a property. To get around this problem, we’re storing a number of identifiers that can be used to recover a reference to the appropriate SPListItem object when the job is deserialized.
Combine Documents Using OpenXML
Before we can make use of OpenXML, we need to add a reference to the OpenXML SDK binaries:
using Word = DocumentFormat.OpenXml.Wordprocessing;
In this code snippet, the CombineDocuments method loads a Microsoft Word format template. The code then searches for all content controls within the document, and where the content control has a title of MergePlaceholder, the contents of all files with a.docx extension within the document set are merged into the template. The merge process makes use of the Alternative Format Import Part control to merge contents. This control inserts a binary copy of data into the template at a specific position. When the completed document is rendered in a client application, the merge is performed dynamically each time the document is opened.
Converting an OpenXML Document to an Alternative Format
Before we can make use of Word Automation Services in our application, we need to add a reference to the appropriate assembly:
We’ve now completed the code required to implement our demonstration scenario. Deploy the project by selecting Deploy SalesProposalApplication from the Build menu.
Customizing Document Set Welcome Page
As you saw, each document set has a welcome page that contains a list of the documents within the set as well as information about the set itself. The web part that we created earlier will be used to customize the welcome page for our Sales Proposal document set so that whenever the content type is used, our custom control will be displayed instead of the built-in DocumentSetProperties control.
Create a Document Library
Before we can begin creating sales proposals, we need to create a new document library that is bound to our Sales Proposal content type.
Create a Document Template
Our final step before we can see our document set functionality in action is to create a template for our compilation process. Since we need to add Content Controls to our template document, we can create the document using Visual Studio.
TIPWhen you select the Upload Document | Upload Multiple Documents option from the Documents tab, the file can be uploaded by dragging and dropping it onto the dialog box. We can now make use of our Sales Proposals document set to create a composite document.
Share Point 2010 Related Interview Questions
|Web Services Interview Questions||XML Interview Questions|
|Share Point 2010 Interview Questions||ASP.NET Interview Questions|
|Share Point Administration Interview Questions||BizTalk Admin Interview Questions|
|Microsoft Office SharePoint Server (MOSS) Interview Questions||Biztalk Server Interview Questions|
|Asp Dot Net Mvc 4 Interview Questions||Biztalk Esb Toolkit Interview Questions|
|InfoPath Interview Questions|
Share Point 2010 Tutorial
The Microsoft Sharepoint 2010 Platform
Developing With Sharepoint 2010
Presentation Layer Overview
Client Object Model
Infopath Forms Services
Enterprise Content Management
User Interface Customization
Application Services Overview
Service Application Framework
Word Automation Services
Data Access Overview
Linq To Sharepoint And Spmetal
Business Connectivity Services
User Profiles And Social Data
Packaging And Deployment Model
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.