Compartilhar via


ItemOperations.IsFileOpen Method

Indicates whether or not the specified saved file is currently open in the specified view.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

Syntax

'Declaration
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

Parameters

  • FileName
    Type: System.String

    Required. The absolute path to the specified saved file. If the file has just been created but not yet saved, then IsFileOpen returns false.

  • ViewKind
    Type: System.String

    Optional. A Constants.vsViewKind* constant representing the type of view in which the saved file is currently open.

Return Value

Type: System.Boolean
A Boolean value indicating true if the file is open in the specified view, false if not.

Examples

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 Security

See Also

Reference

ItemOperations Interface

EnvDTE Namespace