ServerDocument 构造函数 (String) (2007 system)

更新:2007 年 11 月

使用要加载的文档的完整路径,初始化 ServerDocument 类的新实例。

命名空间:  Microsoft.VisualStudio.Tools.Applications
程序集:  Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0(在 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 中)

语法

声明
Public Sub New ( _
    documentPath As String _
)
用法
Dim documentPath As String

Dim instance As New ServerDocument(documentPath)
public ServerDocument(
    string documentPath
)

参数

  • documentPath
    类型:System.String

    要加载的文档的完整路径。

异常

异常 条件
ArgumentNullException

documentPath 参数为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者完全由空白字符组成。

FileNotFoundException

documentPath 指定的文件不存在。

DocumentCustomizedWithPreviousRuntimeException

documentPath 指定的文件具有使用早期版本的 Visual Studio Tools for Office 运行时创建的自定义项。

UnknownCustomizationFileException

Visual Studio Tools for Office 不支持 documentPath 指定的文件的文件扩展名。

备注

使用此构造函数可以访问磁盘上的文档中的缓存数据或部署清单信息。使用此构造函数时,指定的文档以读/写访问权限打开。

示例

下面的代码示例使用 ServerDocument(String) 构造函数来创建一个加载指定文档的新 ServerDocument。然后,该示例显示附加到文档的 Visual Studio Tools for Office 自定义项的部署清单的 URL。

此示例需要在代码文件顶部使用对 Microsoft.VisualStudio.Tools.Applications.ServerDocument.v9.0.dll 和 Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.dll 程序集的引用,并对 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();
    }
}

权限

另请参见

参考

ServerDocument 类

ServerDocument 成员

ServerDocument 重载

Microsoft.VisualStudio.Tools.Applications 命名空间