ServerDocument.RemoveCustomization, méthode

Supprime la personnalisation du document.

Espace de noms :  Microsoft.VisualStudio.Tools.Applications
Assembly :  Microsoft.VisualStudio.Tools.Applications.ServerDocument (dans Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)

Syntaxe

'Déclaration
Public Shared Sub RemoveCustomization ( _
    documentPath As String _
)
public static void RemoveCustomization(
    string documentPath
)

Paramètres

  • documentPath
    Type : System.String
    Chemin d'accès complet du document duquel vous voulez supprimer la personnalisation.

Exceptions

Exception Condition
ArgumentNullException

Le paramètre documentPath est nullune référence null (Nothing en Visual Basic), vide ou ne contient que des espaces.

FileNotFoundException

Le fichier spécifié par documentPath n'existe pas.

IOException

Le fichier spécifié par documentPath est en lecture seule ou est inaccessible.

InvalidOperationException

Le fichier spécifié par documentPath n'a pas de personnalisation ou une erreur s'est produite lors du chargement du manifeste.

DocumentCustomizedWithPreviousRuntimeException

Le fichier spécifié par documentPath a une personnalisation qui n'a pas été créée avec Visual Studio 2010 tools pour Office Runtime ou Visual Studio Tools pour Microsoft Office system (version 3,0 runtime).

Notes

Cette méthode efface l'URL du manifeste de déploiement ainsi que le manifeste des données en mémoire cache et supprime toutes les données en mémoire cache du document.Pour plus d'informations, consultez Comment : supprimer des extensions de code managé de documents.

Exemples

L'exemple de code suivant utilise la méthode RemoveCustomization pour supprimer la personnalisation du document spécifié.L'exemple appelle en premier la méthode GetCustomizationVersion pour déterminer si le document a une personnalisation.

Cet exemple nécessite :

  • Projet d'application console ou un autre projet non-Office.

  • Références aux assemblys suivants :

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll et Microsoft.VisualStudio.Tools.Applications.Runtime.dll (si le projet cible .NET Framework 4 ou .NET Framework 4.5).

      ou

    • Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll et Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (si le projet cible le .NET Framework 3.5).

  • Instructions Imports (pour Visual Basic) ou using pour C#) pour les espaces de noms Microsoft.VisualStudio.Tools.Applications et Microsoft.VisualStudio.Tools.Applications.Runtime au haut de votre fichier de code.

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

Sécurité .NET Framework

Voir aussi

Référence

ServerDocument Classe

Microsoft.VisualStudio.Tools.Applications, espace de noms

Autres ressources

Comment : supprimer des extensions de code managé de documents