Condividi tramite


Metodo ServerDocument.RemoveCustomization

Rimuove la personalizzazione dal documento.

Spazio dei nomi:  Microsoft.VisualStudio.Tools.Applications
Assembly:  Microsoft.VisualStudio.Tools.Applications.ServerDocument (in Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Sintassi

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

Parametri

  • documentPath
    Tipo: System.String
    Percorso completo del documento dal quale si desidera rimuovere la personalizzazione.

Eccezioni

Eccezione Condizione
ArgumentNullException

Il parametro documentPath è nullriferimento null (Nothing in Visual Basic), vuoto oppure composto unicamente da spazi vuoti.

FileNotFoundException

Il file specificato in documentPath non esiste.

IOException

Il file specificato in documentPath è in sola lettura oppure non è accessibile.

InvalidOperationException

Il file specificato da documentPath non include una personalizzazione oppure si è verificato un errore durante il caricamento del manifesto.

DocumentCustomizedWithPreviousRuntimeException

Il file specificato da documentPath dispone di una personalizzazione non creata con Visual Studio 2010 tools per Office runtime o Visual Studio Tools per Microsoft Office System (versione runtime 3,0).

Note

Il metodo cancella l'URL del manifesto di distribuzione e il manifesto dei dati memorizzati nella cache e rimuove eventuali dati memorizzati nella cache dal documento.Per ulteriori informazioni, vedere Procedura: rimuovere estensioni di codice gestito dai documenti.

Esempi

Nell'esempio di codice riportato di seguito viene utilizzato il metodo RemoveCustomization per rimuovere la personalizzazione dal documento specificato.Viene innanzitutto chiamato il metodo GetCustomizationVersion per determinare se il documento include o meno una personalizzazione.

L'esempio presenta i seguenti requisiti:

  • Progetto di applicazione console o qualche altro progetto non-Office.

  • Riferimenti ai seguenti assembly:

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.dll (se il progetto è destinato a .NET Framework 4 o .NET Framework 4.5).

      oppure

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll e Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (se il progetto è destinato a .NET Framework 3.5).

  • Istruzioni Imports (per Visual Basic) o using (per C#) per gli spazi dei nomi Microsoft.VisualStudio.Tools.Applications e Microsoft.VisualStudio.Tools.Applications.Runtime all'inizio del file di codice

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

ServerDocument Classe

Spazio dei nomi Microsoft.VisualStudio.Tools.Applications

Altre risorse

Procedura: rimuovere estensioni di codice gestito dai documenti