更新: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, _
access As FileAccess _
)
用法
Dim documentPath As String
Dim access As FileAccess
Dim instance As New ServerDocument(documentPath, _
access)
public ServerDocument(
string documentPath,
FileAccess access
)
参数
documentPath
类型:System.String要加载的文档的完整路径。
access
类型:System.IO.FileAccess一个指示对文档的文件访问权限的值。
异常
异常 | 条件 |
---|---|
ArgumentNullException | documentPath 参数为 nullnull 引用(在 Visual Basic 中为 Nothing) 或为空,或者完全由空白字符组成。 |
ArgumentException | access 的值为 Write。 |
FileNotFoundException | documentPath 指定的文件不存在。 |
DocumentNotCustomizedException | documentPath 参数指定的文件不具有 Visual Studio Tools for Office 自定义项,并且 access 的值为 Read。 |
DocumentCustomizedWithPreviousRuntimeException | documentPath 指定的文件具有使用早期版本的 Visual Studio Tools for Office 运行时创建的自定义项。 |
UnknownCustomizationFileException | Visual Studio Tools for Office 不支持 documentPath 指定的文件的文件扩展名。 |
备注
如果要以只读或只写访问权限打开磁盘中的文档,则使用此构造函数可以访问该文档中的缓存数据或部署清单信息。默认情况下,其他 ServerDocument 构造函数以读/写访问权限打开文档。
示例
下面的代码示例使用 ServerDocument(String, FileAccess) 构造函数来创建一个以只读访问权限加载指定文档的新 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.Applications 和 Microsoft.VisualStudio.Tools.Applications.Runtime 命名空间使用 Imports(对于 Visual Basic)或 using(对于 C#)语句。
Private Sub CreateServerDocumentReadOnly(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, System.IO.FileAccess.Read)
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 DocumentNotCustomizedException
System.Windows.Forms.MessageBox.Show("The specified document does not " & _
"have a customization.")
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 CreateServerDocumentReadOnly(string documentPath)
{
int runtimeVersion = 0;
ServerDocument serverDocument1 = null;
try
{
runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
if (runtimeVersion == 3)
{
serverDocument1 = new ServerDocument(documentPath,
System.IO.FileAccess.Read);
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 (DocumentNotCustomizedException)
{
System.Windows.Forms.MessageBox.Show("The specified document does not " +
"have a customization.");
}
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();
}
}
权限
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。