Bagikan melalui


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

  • Document-level projects

Microsoft Office version

  • Microsoft Office 2003

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

  1. Create a new project, for example a console application or Windows Forms project.

  2. Add a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime.dll assembly to the project.

  3. 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;
    
  4. 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();
    
  5. 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:

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

To clear the embedded application manifest and cached data from a closed document or a document on a server

  1. Create a new project, for example a console application or Windows Forms project.

  2. Add a reference to the Microsoft.VisualStudio.Tools.Applications.Runtime.dll assembly to the project.

  3. 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;
    
  4. 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

Caching Data

Application and Deployment Manifests in Office Solutions