Sdílet prostřednictvím


ServerDocument.RemoveCustomization – metoda

Vlastní nastavení odstraní 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 bílé znaky.

FileNotFoundException

Do souboru určeného parametrem documentPath neexistuje.

IOException

Do souboru určeného parametrem documentPath je jen pro čtení, nebo nelze získat přístup.

InvalidOperationException

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

DocumentCustomizedWithPreviousRuntimeException

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

Poznámky

Tato metoda odstraní adresu URL manifestu nasazení a manifestu data uložená v mezipaměti a z dokumentu odstraní všechna data uložená v mezipaměti.Další informace naleznete v tématu Postupy: Odebrání rozšíření spravovaného kódu z dokumentů.

Příklady

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

Tento příklad vyžaduje:

  • Projekt aplikace konzoly 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 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 Visual Basic) nebo using (pro jazyk C#) příkazy pro Microsoft.VisualStudio.Tools.Applications a Microsoft.VisualStudio.Tools.Applications.Runtime obory názvů v horní části 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

Postupy: Odebrání rozšíření spravovaného kódu z dokumentů