共用方式為


AddCustomization 方法 (String, String, String, String, Boolean) (2003 系統)

將新的應用程式資訊清單加入至指定的文件。

命名空間:  Microsoft.VisualStudio.Tools.Applications.Runtime
組件:  Microsoft.VisualStudio.Tools.Applications.Runtime (在 Microsoft.VisualStudio.Tools.Applications.Runtime.dll 中)

語法

'宣告
Public Shared Function AddCustomization ( _
    documentPath As String, _
    assemblyName As String, _
    deploymentManifestPath As String, _
    applicationVersion As String, _
    makePathsRelative As Boolean _
) As String
'用途
Dim documentPath As String
Dim assemblyName As String
Dim deploymentManifestPath As String
Dim applicationVersion As String
Dim makePathsRelative As Boolean
Dim returnValue As String

returnValue = ServerDocument.AddCustomization(documentPath, _
    assemblyName, deploymentManifestPath, _
    applicationVersion, makePathsRelative)
public static string AddCustomization(
    string documentPath,
    string assemblyName,
    string deploymentManifestPath,
    string applicationVersion,
    bool makePathsRelative
)

參數

  • applicationVersion
    型別:System. . :: .String

    應用程式資訊清單的版本是由主要版本、次要版本、組建編號和修定編號所指定,並以句號 (.) 分隔。

  • makePathsRelative
    型別:System. . :: .Boolean

    true 表示將應用程式資訊清單中所有的路徑設為相對於文件的位置,false 表示將所有的路徑設為絕對路徑。

傳回值

型別:System. . :: .String

XML 字串,包含新應用程式資訊清單的內容。

例外狀況

例外狀況 條件
ArgumentNullException

documentPath、assemblyName 或 applicationVersion 參數為 null Nothing nullptr Null 參照 (即 Visual Basic 中的 Nothing) 或空白。

FileNotFoundException

documentPath 或 assemblyName 參數參考不存在的檔案。

InvalidOperationException

documentPath 所指定的文件已經含有 Visual Studio Tools for Office 自訂。

ArgumentException

applicationVersion 參數的格式無效。

COMException

documentPath 所指定的文件沒有 Runtime Storage Control,且文件所在的電腦上未安裝文件適用的 Microsoft Office 應用程式。

備註

AddCustomization(String, String, String, String, Boolean) 方法會將多個項目加入至應用程式資訊清單,這些項目表示指定的方案組件、部署資訊清單和應用程式資訊清單的版本。如需應用程式和部署資訊清單的詳細資訊,請參閱 Office 方案中的應用程式和部署資訊清單

這個方法會將 Runtime Storage Control 加入至文件 (如果文件尚未有此控制項)。這個程序需要文件位於已安裝 Microsoft Office Word (針對 Word 文件) 或 Microsoft Office Excel (針對 Excel 活頁簿) 的電腦上。如需 Runtime Storage Control 的詳細資訊,請參閱 Runtime Storage Control 概觀

如果指定的文件未包含控制項,而該控制項為方案組件要求文件所必須具備,則 AddCustomization(String, String, String, String, Boolean) 方法會成功,但是當使用者開啟文件時,會無法載入組件。

applicationVersion 參數必須是字串,指定主要版本、次要版本、組建編號和修定編號,並以句號 (.) 分隔。例如 1.0.0 是無效的,但是 1.0.0.1 是有效的。

範例

下列程式碼範例會使用 AddCustomization(String, String, String, String, Boolean) 方法,使用指定的組件和部署資訊清單,將新的應用程式資訊清單加入至指定的文件。這個範例需要對 Microsoft.VisualStudio.Tools.Applications.Runtime 組件的參考,並且在程式碼檔的開頭需要 Microsoft.VisualStudio.Tools.Applications.Runtime 命名空間的 Imports (適用於 Visual Basic) 或 using (適用於 C#) 陳述式。

Private Sub AddNewCustomization(ByVal fileName As String)
    If Not ServerDocument.IsCustomized(fileName) Then
        Dim assemblyName As String = "ExcelApplication1.dll"
        Dim deploymentManifestPath As String = _
            "\\servername\deployshare\ExcelApplication1.application"
        Dim applicationVersion As String = "1.0.0.1"
        Dim newManifest As String = ServerDocument.AddCustomization( _
            fileName, assemblyName, deploymentManifestPath, _
            applicationVersion, False)
        MsgBox("The document has been customized.")
    Else
        MsgBox("The specified document is already " + _
            "customized.")
    End If
End Sub
private void AddNewCustomization(string fileName)
{
    if (!ServerDocument.IsCustomized(fileName))
    {
        string assemblyName = "ExcelApplication1.dll";
        string deploymentManifestPath =
            @"\\servername\deployshare\ExcelApplication1.application";
        string applicationVersion = "1.0.0.1";

        string newManifest = ServerDocument.AddCustomization(
            fileName, assemblyName, deploymentManifestPath, 
            applicationVersion, false);

        MessageBox.Show("The document has been customized.");
    }
    else
    {
        MessageBox.Show("The specified document is already " +
            "customized.");
    }
}

使用權限

請參閱

參考

ServerDocument 類別

ServerDocument 成員

AddCustomization 多載

Microsoft.VisualStudio.Tools.Applications.Runtime 命名空間

其他資源

Runtime Storage Control 概觀

Office 方案中的應用程式和部署資訊清單