ItemOperations.IsFileOpen 方法

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

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

语法

声明
Function IsFileOpen ( _
    FileName As String, _
    ViewKind As String _
) As Boolean
bool IsFileOpen(
    string FileName,
    string ViewKind
)
bool IsFileOpen(
    [InAttribute] String^ FileName, 
    [InAttribute] String^ ViewKind
)
abstract IsFileOpen : 
        FileName:string * 
        ViewKind:string -> bool
function IsFileOpen(
    FileName : String, 
    ViewKind : String
) : boolean

参数

  • FileName
    类型:String

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

  • ViewKind
    类型:String

    可选。 目前打开的保存文件中表示视图类型的 Constants .vsViewKind* 常数。

返回值

类型: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

.NET Framework 安全性

请参阅

参考

ItemOperations 接口

EnvDTE 命名空间