Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

ServerDocument.RemoveCustomization Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Removes the customization from the document.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
public static void RemoveCustomization(
	string documentPath
)

Parameters

documentPath
Type: System.String

The full path of the document from which you want to remove the customization.

ExceptionCondition
ArgumentNullException

The documentPath parameter is null or empty or consists completely of white space characters.

FileNotFoundException

The file specified by documentPath does not exist.

IOException

The file specified by documentPath is read-only, or cannot be accessed.

InvalidOperationException

The file specified by documentPath does not have a customization, or an error occurred while loading the manifest.

DocumentCustomizedWithPreviousRuntimeException

The file specified by documentPath has a customization that was not created with the Visual Studio 2010 Tools for Office Runtime or the Visual Studio Tools for the Microsoft Office system (version 3.0 Runtime).

This method clears the deployment manifest URL and the cached data manifest, and removes any cached data from the document. For more information, see How to: Remove Managed Code Extensions from Documents.

The following code example uses the RemoveCustomization method to remove the customization from the specified document. The example first calls the GetCustomizationVersion method to determine whether the document has a customization.

This example requires:

  • A console application project or some other non-Office project.

  • References to the following assemblies:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.dll (if the project targets the .NET Framework 4 or the .NET Framework 4.5).

      or

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll and Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (if the project targets the .NET Framework 3.5).

  • Imports (for Visual Basic) or using (for C#) statements for Microsoft.VisualStudio.Tools.Applications and Microsoft.VisualStudio.Tools.Applications.Runtime namespaces at the top of your code file.

private static void RemoveAssembly(string documentPath)
{
    int runtimeVersion = 0;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);

        // Make sure that this customization was created using the correct runtime. 
        if (runtimeVersion != 3)
        {
            MessageBox.Show("This document does not have a Visual Studio Tools for " +
                "Office customization, or it has a customization that was created with " +
                "a version of the runtime that is incompatible with this version of the " +
                "ServerDocument class.");
            return;
        }

        ServerDocument.RemoveCustomization(documentPath);
        MessageBox.Show("The customization has been removed.");
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (System.IO.IOException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document is read-only.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    catch (InvalidOperationException ex)
    {
        System.Windows.Forms.MessageBox.Show("The customization could not be removed.\n" +
            ex.Message);
    }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.