ItemOperations.IsFileOpen 方法

更新:2007 年 11 月

指示指定的已保存文件当前是否已在指定视图中打开。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Function IsFileOpen ( _
    FileName As String, _
    ViewKind As String _
) As Boolean
用法
Dim instance As ItemOperations
Dim FileName As String
Dim ViewKind As String
Dim returnValue As Boolean

returnValue = instance.IsFileOpen(FileName, _
    ViewKind)
bool IsFileOpen(
    string FileName,
    string ViewKind
)
bool IsFileOpen(
    [InAttribute] String^ FileName, 
    [InAttribute] String^ ViewKind
)
function IsFileOpen(
    FileName : String, 
    ViewKind : String
) : boolean

参数

  • FileName
    类型:System.String

    必需。指定的已保存文件的绝对路径。如果文件只是已创建但尚未保存,则 IsFileOpen 返回 false。

  • ViewKind
    类型:System.String

    可选。一个 Constants.vsViewKind* 常数,它表示当前打开保存的文件所用的视图类型。

返回值

类型:System.Boolean

一个布尔值,如果以指定视图打开文件,则为 true,否则为 false。

示例

Sub IsFileOpenExample()
    Dim soln As Solution = DTE.Solution
    Dim prj As Project
    Dim prjItem As ProjectItem
    Dim ItemOp As ItemOperations
    Dim savePath As String

    ' Create a new text document.
    ItemOp = DTE.ItemOperations
    ItemOp.NewFile("General\Text File", "Some name", _
    Constants.vsViewKindTextView)

    ' Set variables for proj and proj item names.
    prj = soln.Item(1)
    prjItem = prj.ProjectItems.Item(1)
    savePath = "C:\UserFiles\KempB\" & prjItem.Name
    MsgBox(savePath)

    If ItemOp.IsFileOpen(savePath) = True Then
        MsgBox("The saved document is open.")
    Else
        MsgBox("The saved document is not open.")
    End If

    prjItem.Save(savePath)
        
    If ItemOp.IsFileOpen(savePath) = True Then
        MsgBox("The saved document is open.")
    Else
        MsgBox("The saved document is not open.")
    End If
End Sub

权限

另请参见

参考

ItemOperations 接口

ItemOperations 成员

EnvDTE 命名空间