Detaching a Solution from a Document Using Server Document

A common detaching scenario involves document generation. For example, imagine that you have created a VSTO solution that pulls data from a database to generate an invoice document. The user opens the VSTO template file, which creates a new VSTO document instance. The user then uses the actions pane, data binding, and other VSTO features to generate the invoice. When you send a document in e-mail, you're not sending the assembly along with it. Even if you did, the user wouldn't have permission to run the solution.

The customer requires that you send the invoice as an uncustomized Word or Excel document. The solution is to detach the VSTO solution from the document before you send it. Listing 13.1 shows how to detach a VSTO solution from a document using a Console application. After you detach the VSTO solution, the customization is no longer associated with the document, and it can be opened and used by any user who has any version of Office 2003 or the Office 2003 viewers.

Listing 13.1. Detaching a VSTO solution from a document

Imports Microsoft.VisualStudio.Tools.Applications.Runtime

Module Modulel

Sub Main()

' Path to VSTO document.

Dim documentPath As String = "C:\Invoice\Invoice.xls" 'Detach the VSTO solution from the document. DetachSolution(documentPath)

End Sub

Sub DetachSolution(ByVal documentPath As String)

' Check to see whether the document is a VSTO solution. If ServerDocument.IsCustomized(documentPath) Then

' Remove VSTO solution to make a normal document ' again.

ServerDocument.RemoveCustomization(documentPath) End If End Sub End Module

0 0

Post a comment