ServerDocument.RemoveCustomization - метод
Удаляет настройку из документа.
Пространство имен: Microsoft.VisualStudio.Tools.Applications
Сборка: Microsoft.VisualStudio.Tools.Applications.ServerDocument (в Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll)
Синтаксис
'Декларация
Public Shared Sub RemoveCustomization ( _
documentPath As String _
)
public static void RemoveCustomization(
string documentPath
)
Параметры
- documentPath
Тип: System.String
Полный путь к документу, из которого необходимо удалить настройку.
Исключения
Исключение | Условие |
---|---|
ArgumentNullException | Параметр documentPath равен nullпустая ссылка (Nothing в Visual Basic), пуст или содержит только пробелы. |
FileNotFoundException | Файл, заданный в параметре documentPath, не существует. |
IOException | Заданный в параметре documentPath файл доступен только для чтения, или доступ к нему отсутствует. |
InvalidOperationException | Файл, заданный параметром documentPath, не имеет настройки, или при загрузке манифеста возникла ошибка. |
DocumentCustomizedWithPreviousRuntimeException | Файл, указанный параметром documentPath, содержит настройку, которая не была создана с помощью Visual Studio 2010 Tools для среды выполнения Office или Visual Studio Tools для системы Microsoft Office (версия среды выполнения 3.0). |
Заметки
Этот метод очищает URL-адрес манифеста развертывания и манифеста кэшированных данных, а также удаляет любые кэшированные данные из документа. Дополнительные сведения см. в разделе Практическое руководство. Удаление расширений управляемого кода из документов.
Примеры
В следующем примере кода используется метод RemoveCustomization для удаления настройки из указанного документа. В примере сначала вызывается метод GetCustomizationVersion, чтобы определить, есть ли в документе настройка.
Для этого примера требуется:
Проект консольного приложения или другой проект, не связанный с Office.
Ссылки на следующие сборки:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll и Microsoft.VisualStudio.Tools.Applications.Runtime.dll (если проект предназначен для платформы .NET Framework 4).
или
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll и Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll (если проект предназначен для платформы .NET Framework 3.5).
Операторы 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);
}
}
Безопасность платформы .NET Framework
- Полное доверие для непосредственно вызывающего метода. Этот член не может быть использован частично доверенным кодом. Дополнительные сведения см. в разделе Использование библиотек из не вполне надежного кода.
См. также
Ссылки
Microsoft.VisualStudio.Tools.Applications - пространство имен
Другие ресурсы
Практическое руководство. Удаление расширений управляемого кода из документов