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 参数为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者完全由空白字符组成。 |
FileNotFoundException | documentPath 指定的文件不存在。 |
IOException | documentPath 指定的文件是只读文件,或者不能访问。 |
InvalidOperationException | documentPath 指定的文件不具有自定义项,或者在加载清单时出错。 |
DocumentCustomizedWithPreviousRuntimeException | 由 documentPath 指定的文件有非 Visual Studio 2010 Tools for Office Runtime 或 Visual Studio Tools for the Microsoft Office system (3.0 版的运行时)创建的自定义。 |
备注
此方法清除部署清单 URL 和缓存数据清单,并从文档中移除所有缓存数据。有关更多信息,请参见如何:移除文档中的托管代码扩展。
示例
下面的代码示例使用 RemoveCustomization 方法从指定文档中移除自定义。此示例首先调用 GetCustomizationVersion 方法,以确定文档是否具有自定义项。
此示例需要:
控制台应用程序项目或某些其他非 Office 项目。
对下列程序集的引用:
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll 和 Microsoft.VisualStudio.Tools.Applications.Runtime.dll (如果项目面向 .NET Framework 4 或 .NET Framework 4.5)。
或
Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0.dll 和 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll(如果该项目面向 .NET Framework 3.5)。
位于代码文件顶部的用于 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);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。
请参见
参考
Microsoft.VisualStudio.Tools.Applications 命名空间