共用方式為


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 系統 (3.0 版執行階段) 建立的自訂。

備註

這個方法會清除部署資訊清單 URL 和快取資料資訊清單,並移除文件中的快取資料。 如需詳細資訊,請參閱HOW TO:從文件移除 Managed 程式碼擴充

範例

下列程式碼範例會使用 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.ApplicationsMicrosoft.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 安全性

請參閱

參考

ServerDocument 類別

Microsoft.VisualStudio.Tools.Applications 命名空間

其他資源

HOW TO:從文件移除 Managed 程式碼擴充