ServerDocument.RemoveCustomization 方法 (2007 system)
更新:2007 年 11 月
从文档中移除 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 参数为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者完全由空白字符组成。 |
FileNotFoundException | documentPath 指定的文件不存在。 |
IOException | documentPath 指定的文件是只读文件,或者不能访问。 |
InvalidOperationException | documentPath 指定的文件不具有 Visual Studio Tools for Office 自定义项,或者在加载清单时出错。 |
DocumentCustomizedWithPreviousRuntimeException | documentPath 指定的文件具有使用早期版本的 Visual Studio Tools for Office 运行时创建的自定义项。 |
备注
此方法清除部署清单 URL 和缓存数据清单,并从文档中移除所有缓存数据。有关更多信息,请参见如何:移除文档中的托管代码扩展 (2007 System)。
示例
下面的代码示例使用 RemoveCustomization 方法从指定文档中移除自定义。此示例首先调用 GetCustomizationVersion 方法,以确定文档是否具有 Visual Studio Tools for Office 自定义项。
此示例需要在代码文件顶部使用对 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 和 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll 程序集的引用,并对 Microsoft.VisualStudio.Tools.Applications 和 Microsoft.VisualStudio.Tools.Applications.Runtime 命名空间使用 Imports(对于 Visual Basic)或 using(对于 C#)语句。
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);
}
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
另请参见
参考
Microsoft.VisualStudio.Tools.Applications 命名空间