Share via


ServerDocument.RemoveCustomization – metoda

Vlastní nastavení odebere z dokumentu.

Obor názvů:  Microsoft.VisualStudio.Tools.Applications
Sestavení:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (v Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntaxe

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

Parametry

  • documentPath
    Typ: System.String
    Úplná cesta dokumentu, ze kterého chcete odebrat vlastní nastavení.

Výjimky

Výjimka Podmínka
ArgumentNullException

documentPath Parametr je nullodkaz null (Nothing v jazyce Visual Basic) prázdný nebo obsahuje zcela prázdné znaky.

FileNotFoundException

Souboru určeného parametrem documentPath neexistuje.

IOException

Souboru určeného parametrem documentPath je určena jen pro čtení nebo není přístupný.

InvalidOperationException

Souboru určeného parametrem documentPath nemá o přizpůsobení nebo došlo k chybě došlo při načítání manifestu.

DocumentCustomizedWithPreviousRuntimeException

Souboru určeného parametrem documentPath má vlastní nastavení, která nebyla vytvořena pomocí nástroje sady Visual Studio 2010 Runtime sady Office nebo Visual Studio Tools for the Microsoft Office system (verze 3.0 Runtime).

Poznámky

Tato metoda vymaže URL manifestu nasazení a manifestu data uložená v mezipaměti a odstraní všechna data uložená v mezipaměti z dokumentu. Další informace naleznete v tématu Jak: z dokumentů odebrat rozšíření spravovaný kód.

Příklady

Následující příklad kódu používá RemoveCustomization způsob odebrání vlastního nastavení ze zadaného dokumentu. Příklad první volání GetCustomizationVersion metoda k určení, zda dokument o přizpůsobení.

Tento příklad vyžaduje:

  • Projekt konzolové aplikace nebo jiného projektu mimo sadu Office.

  • Odkazy na následující sestavení:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.dll (Pokud bude projekt cílen .NET Framework 4 nebo .NET Framework 4.5).

      nebo

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll a Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (Pokud je projekt cílen na rozhraní.NET Framework 3.5).

  • Imports(pro jazyk Visual Basic) nebo using (pro jazyk C#) příkazy pro Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů na začátku souboru kódu.

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

Zabezpečení rozhraní .NET Framework

Viz také

Referenční dokumentace

ServerDocument Třída

Microsoft.VisualStudio.Tools.Applications – obor názvů

Další zdroje

Jak: z dokumentů odebrat rozšíření spravovaný kód