Поделиться через


ServerDocument.RemoveCustomization Метод (2007 System)

Обновлен: Ноябрь 2007

Удаляет из документа настройку Visual Studio Tools for Office.

Пространство имен:  Microsoft.VisualStudio.Tools.Applications
Сборка:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0 (в Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll)

Синтаксис

'Декларация
Public Shared Sub RemoveCustomization ( _
    documentPath As String _
)
'Применение
Dim documentPath As String

ServerDocument.RemoveCustomization(documentPath)
public static void RemoveCustomization(
    string documentPath
)

Параметры

  • documentPath
    Тип: System.String
    Полный путь к документу, из которого необходимо удалить настройку.

Исключения

Исключение Условие
ArgumentNullException

Параметр documentPath равен nullссылка null (Nothing в Visual Basic), пуст или содержит только пробелы.

FileNotFoundException

Файл, заданный в параметре documentPath, не существует.

IOException

Заданный в параметре documentPath файл доступен только для чтения, или доступ к нему отсутствует.

InvalidOperationException

Файл, заданный с помощью documentPath, не имеет настройку Visual Studio Tools for Office или при загрузке манифеста возникла ошибка.

DocumentCustomizedWithPreviousRuntimeException

Файл, заданный в параметре documentPath, имеет настройку, созданную в предыдущей версии среды выполнения Visual Studio Tools for Office.

Заметки

Этот метод очищает URL-адрес манифеста развертывания и манифеста кэшированных данных, а также удаляет любые кэшированные данные из документа. Дополнительные сведения см. в разделе Практическое руководство. Удаление расширений управляемого кода из документов (система 2007).

Примеры

В следующем примере кода используется метод RemoveCustomization для удаления настройки из указанного документа. В примере сначала вызывается метод GetCustomizationVersion, чтобы определить, есть ли в документе настройка Visual Studio Tools for Office.

Для этого примера требуются ссылки на сборки Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll, Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll и операторы Imports (в Visual Basic) или using (в C#) для пространств имен Microsoft.VisualStudio.Tools.Applications и Microsoft.VisualStudio.Tools.Applications.Runtime в начале файла с кодом.

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

Разрешения

См. также

Ссылки

ServerDocument Класс

ServerDocument - члены

Microsoft.VisualStudio.Tools.Applications - пространство имен

Другие ресурсы

Практическое руководство. Удаление расширений управляемого кода из документов (система 2007)