This topic has not yet been rated - Rate this topic

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)

bool IsFileOpen (
	[InAttribute] string FileName,
	[OptionalAttribute] [InAttribute] string ViewKind
)
boolean IsFileOpen (
	/** @attribute InAttribute() */ String FileName, 
	/** @attribute InAttribute() */ /** @attribute OptionalAttribute() */ String ViewKind
)
function IsFileOpen (
	FileName : String, 
	ViewKind : String
) : boolean

Parameters

FileName

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

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

Return Value

A Boolean value indicating true if the file is open in the specified view, false if not.
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
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Advertisement