Compartilhar via


ItemOperations.IsFileOpen(String, String) Method

Definition

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

bool IsFileOpen(std::wstring const & FileName, std::wstring const & ViewKind = "{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}");
[System.Runtime.InteropServices.DispId(5)]
public bool IsFileOpen (string FileName, string ViewKind = "{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}");
[<System.Runtime.InteropServices.DispId(5)>]
abstract member IsFileOpen : string * string -> bool
Public Function IsFileOpen (FileName As String, Optional ViewKind As String = "{FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF}") As Boolean

Parameters

FileName
String

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

ViewKind
String

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

Returns

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

Attributes

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  

Applies to