Share via


ServerDocument 建構函式 (String)

使用要載入之文件的完整路徑,初始化 ServerDocument 類別的新執行個體。

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

語法

'宣告
Public Sub New ( _
    documentPath As String _
)
public ServerDocument(
    string documentPath
)

參數

  • documentPath
    型別:System.String
    要載入之文件的完整路徑。

例外狀況

例外狀況 條件
ArgumentNullException

documentPath 參數為 nullNull 參照 (即 Visual Basic 中的 Nothing),或空字串,或整個都是空白字元。

FileNotFoundException

documentPath 所指定的檔案不存在。

DocumentCustomizedWithPreviousRuntimeException

documentPath 指定的檔案具有不以 Visual Studio 2010 Tools for Office Runtime 或 Visual Studio Tools for the Microsoft Office 系統 (3.0 版執行階段) 建立的自訂。

UnknownCustomizationFileException

documentPath 所指定的檔案有 Visual Studio Tools for Office Runtime 不支援的副檔名。

備註

使用這個建構函式存取磁碟上之文件的快取資料或部署資訊清單資訊。 當您使用這個建構函式時,指定的文件會以讀取/寫入存取權開啟。

範例

在下列程式碼範例中,會使用 ServerDocument(String) 建構函式建立新的 ServerDocument 物件,以載入指定的文件。 範例接著會顯示附加至文件之自訂的部署資訊清單 URL。

這個範例需要:

  • 主控台應用程式專案或其他非 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)。

  • Microsoft.VisualStudio.Tools.ApplicationsMicrosoft.VisualStudio.Tools.Applications.Runtime 命名空間 (在程式碼檔最頂端) 的Imports (Visual Basic) 或 using (C#) 陳述式。

Private Sub CreateServerDocumentFromPath(ByVal documentPath As String)
    Dim runtimeVersion As Integer = 0
    Dim serverDocument1 As ServerDocument = Nothing

    Try
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath)
        If runtimeVersion = 3 Then
            serverDocument1 = New ServerDocument(documentPath)
            MessageBox.Show("The URL of the deployment manifest is: " & vbLf & _
                serverDocument1.DeploymentManifestUrl.ToString())
        End If

    Catch ex As System.IO.FileNotFoundException
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.")
    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.")
    Finally
        If Not (serverDocument1 Is Nothing) Then
            serverDocument1.Close()
        End If
    End Try
End Sub
private void CreateServerDocumentFromPath(string documentPath)
{
    int runtimeVersion = 0;
    ServerDocument serverDocument1 = null;

    try
    {
        runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
        if (runtimeVersion == 3)
        {
            serverDocument1 = new ServerDocument(documentPath);
            MessageBox.Show("The URL of the deployment manifest is: \n" +
                serverDocument1.DeploymentManifestUrl.ToString());
        }
    }
    catch (System.IO.FileNotFoundException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
    }
    catch (UnknownCustomizationFileException)
    {
        System.Windows.Forms.MessageBox.Show("The specified document has a file " +
            "extension that is not supported by Visual Studio Tools for Office.");
    }
    finally
    {
        if (serverDocument1 != null)
            serverDocument1.Close();
    }
}

.NET Framework 安全性

請參閱

參考

ServerDocument 類別

ServerDocument 多載

Microsoft.VisualStudio.Tools.Applications 命名空間