Share via


ServerDocument.RemoveCustomization-Methode

Entfernt die Anpassung aus dem Dokument.

Namespace:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntax

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

Parameter

  • documentPath
    Typ: System.String
    Der vollständige Pfad des Dokuments, aus dem Sie die Anpassung entfernen möchten.

Ausnahmen

Ausnahme Bedingung
ArgumentNullException

Der documentPath-Parameter ist entweder nullein Nullverweis (Nothing in Visual Basic) oder leer, oder er besteht nur aus Leerzeichen.

FileNotFoundException

Die in documentPath angegebene Datei ist nicht vorhanden.

IOException

Die in documentPath angegebene Datei ist schreibgeschützt, oder es kann nicht darauf zugegriffen werden.

InvalidOperationException

Die in documentPath angegebene Datei verfügt über keine Anpassung, oder beim Laden des Manifests ist ein Fehler aufgetreten.

DocumentCustomizedWithPreviousRuntimeException

Die von documentPath angegebene Datei bietet eine Anpassung, die nicht mit der Visual Studio 2010-Tools für Office-Laufzeit oder den Visual Studio-Tools für das Microsoft Office-System (Version 3.0 Laufzeit) erstellt wurde.

Hinweise

Diese Methode löscht die Bereitstellungsmanifest-URL und das zwischengespeicherte Datenmanifest und entfernt sämtliche zwischengespeicherten Daten aus dem Dokument.Weitere Informationen finden Sie unter Gewusst wie: Entfernen von Erweiterungen durch verwalteten Code aus Dokumenten.

Beispiele

Im folgenden Codebeispiel wird die RemoveCustomization-Methode verwendet, um die Anpassung aus dem angegebenen Dokument zu entfernen.Im Beispiel wird zuerst die GetCustomizationVersion-Methode aufgerufen, um zu bestimmen, ob das Dokument über eine Anpassung verfügt.

Dieses Beispiel setzt Folgendes voraus:

  • Ein Konsolenanwendungsprojekt oder ein anderes Nicht-Office-Projekt.

  • Verweise auf die folgenden Assemblys:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll und Microsoft.VisualStudio.Tools.Applications.Runtime.dll (wenn das Projekt .NET Framework 4 oder .NET Framework 4.5 abzielt).

      oder

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll und Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (wenn das Projekt auf .NET Framework 3.5 abzielt).

  • Imports-Anweisungen (für Visual Basic) oder using-Anweisungen (für C#) für Microsoft.VisualStudio.Tools.Applications- und Microsoft.VisualStudio.Tools.Applications.Runtime-Namespaces am Anfang der Codedatei.

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);
    }
}

.NET Framework-Sicherheit

Siehe auch

Referenz

ServerDocument Klasse

Microsoft.VisualStudio.Tools.Applications-Namespace

Weitere Ressourcen

Gewusst wie: Entfernen von Erweiterungen durch verwalteten Code aus Dokumenten