How to: Remove Managed Code Extensions from Documents (2003 System)
Applies to |
---|
The information in this topic applies only to the specified Visual Studio Tools for Office projects and versions of Microsoft Office. Project type
Microsoft Office version
For more information, see Features Available by Application and Project Type. |
You can programmatically remove the Visual Studio Tools for Office customization assembly from a document or workbook that is part of a document-level customization for Microsoft Office 2003. Users can then open the documents and view the contents, but any custom user interface (UI) you add to the documents will not appear, and your code will not run. When you remove the assembly, you can choose to leave the cached data in the document or remove it:
If you want to keep the cached data, clear the application manifest that is embedded in the document. You might want to keep the cached data if it will be read later by an ASP.NET page or server application.
If you no longer need the cached data, clear both the application manifest and the cached data.
The Visual Studio Tools for Office runtime includes an object model that enables you to programmatically perform these actions.
Clearing the Embedded Application Manifest
Use the ServerDocument class to clear only the embedded application manifest. You must put code that uses the ServerDocument class in a new project (not your Visual Studio Tools for Office solution), for example in a console application or Windows Forms project.
To clear the embedded application manifest
Create a new project, for example a console application or Windows Forms project.
Add a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime.dll assembly to the project.
Add the following Imports or using statement to the top of your code file.
Imports Microsoft.VisualStudio.Tools.Applications.Runtime
using Microsoft.VisualStudio.Tools.Applications.Runtime;
Create an instance of ServerDocument, and pass in the solution document. Call the Clear method of the AppManifest property.
Dim sd As ServerDocument = Nothing Try sd = New ServerDocument("C:\Documents\SolutionDocument.doc") sd.AppManifest.Clear()
ServerDocument sd = null; try { sd = new ServerDocument(@"C:\Documents\SolutionDocument.doc"); sd.AppManifest.Clear();
Save your changes and close the document.
sd.Save() Finally If Not sd Is Nothing Then sd.Close() End If End Try
sd.Save(); } finally { if (sd != null) { sd.Close(); } }
Clearing the Embedded Application Manifest and Cached Data
You can clear both the embedded application manifest and cached data from the document by using one of the RemoveCustomization methods:
For an open document on a client computer, use the Document.RemoveCustomization or Workbook.RemoveCustomization method.
For a closed document or a document on a server, use the ServerDocumentRemoveCustomization(String) method.
Note
The Document.RemoveCustomization and Workbook.RemoveCustomization methods also remove the Runtime Storage Control from the document. For more information about the Runtime Storage Control, see Runtime Storage Control Overview.
To clear the embedded application manifest and cached data from an open document on a client computer
- In your document-level project for Microsoft Office Word or Microsoft Office Excel, call the Document.RemoveCustomization (for Word) or Workbook.RemoveCustomization (for Excel) method.
To clear the embedded application manifest and cached data from a closed document or a document on a server
Create a new project, for example a console application or Windows Forms project.
Add a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime.dll assembly to the project.
Add the following Imports or using statement to the top of your code file.
Imports Microsoft.VisualStudio.Tools.Applications.Runtime
using Microsoft.VisualStudio.Tools.Applications.Runtime;
Call the static RemoveCustomization(String) method of the ServerDocument class, and specify the solution document path for the parameter.
If (ServerDocument.IsCustomized("C:\Documents\SolutionDocument.doc")) Then ServerDocument.RemoveCustomization("C:\Documents\SolutionDocument.doc") End If
if (ServerDocument.IsCustomized(@"C:\Documents\SolutionDocument.doc")) { ServerDocument.RemoveCustomization(@"C:\Documents\SolutionDocument.doc"); }
See Also
Tasks
How to: Write Code that Uses Both Versions of the ServerDocument Class
How to: Attach Managed Code Extensions to Documents (2003 System)
How to: Remove Managed Code Extensions from Documents (2007 System)
How to: Attach Managed Code Extensions to Documents (2007 System)
Concepts
Managing Documents on a Server by Using the ServerDocument Class