Metoda ServerDocument.RemoveCustomization —

Usuwa dostosowania dokumentu.

Przestrzeń nazw:  Microsoft.VisualStudio.Tools.Applications
Zestaw:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (w Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Składnia

'Deklaracja
Public Shared Sub RemoveCustomization ( _
    documentPath As String _
)
public static void RemoveCustomization(
    string documentPath
)

Parametry

  • documentPath
    Typ: System.String
    Pełna ścieżka dokumentu, z którego chcesz usunąć dostosowanie.

Wyjątki

Wyjątek Warunek
ArgumentNullException

documentPath Jest parametr nullodwołanie o wartości null (Nothing w języku Visual Basic) lub pusta albo składa się wyłącznie z białych spacji.

FileNotFoundException

W pliku określonym przez documentPath nie istnieje.

IOException

W pliku określonym przez documentPath jest tylko do odczytu lub jest niedostępny.

InvalidOperationException

W pliku określonym przez documentPath czy nie ma pliku dostosowań, lub wystąpił błąd podczas ładowania manifest.

DocumentCustomizedWithPreviousRuntimeException

W pliku określonym przez documentPath ma dostosowania, który nie został utworzony z programu Visual Studio 2010 Tools dla środowiska Office Runtime lub Visual Studio Tools dla pakietu Microsoft Office system (wersja 3.0 Runtime).

Uwagi

Ta metoda powoduje wyczyszczenie adresu URL manifestu wdrażania i manifest buforowanych danych i usunie wszystkie buforowane dane z dokumentu.Aby uzyskać więcej informacji, zobacz Porady: usuwanie rozszerzenia kodu zarządzanego z dokumentów.

Przykłady

Następujący kod w przykładzie wykorzystano RemoveCustomization metoda, aby usunąć dostosowanie z określonego dokumentu.Przykład pierwszych zaproszeniach GetCustomizationVersion do określenia, czy dokument zawiera dostosowania.

W tym przykładzie wymaga:

  • Projekt aplikacji konsoli lub innych projektów nienależących do pakietu Office.

  • Odwołania do następujących zestawów:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.dll (jeśli cele projektu .NET Framework 4 lub .NET Framework 4.5).

      lub

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll i Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Jeśli projekt jest przeznaczony dla.NET Framework 3.5).

  • Imports(dla Visual Basic) lub using (w przypadku C#) oświadczenia dla Microsoft.VisualStudio.Tools.Applications i Microsoft.VisualStudio.Tools.Applications.Runtime obszarów nazw u góry pliku kodu.

Private Shared Sub RemoveAssembly(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0

    Try
        ' Make sure that this customization was created using the correct runtime.
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion <> 3 Then
            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
        End If

        ServerDocument.RemoveCustomization(documentPath)
        MessageBox.Show("The customization has been removed.")

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    Catch ex As System.IO.IOException
        System.Windows.Forms.MessageBox.Show("The specified document is read-only.")
    Catch ex As UnknownCustomizationFileException
        System.Windows.Forms.MessageBox.Show("The specified document has a file " & _
            "extension that is not supported by Visual Studio Tools for Office.")
    Catch ex As InvalidOperationException
        System.Windows.Forms.MessageBox.Show("The customization could not be removed." & _
            vbLf & ex.Message)
    End Try
End Sub
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);
    }
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

ServerDocument Klasa

Przestrzeń nazw Microsoft.VisualStudio.Tools.Applications

Inne zasoby

Porady: usuwanie rozszerzenia kodu zarządzanego z dokumentów