/// <summary> /// Returns an IVsTextView for the given file path if the file is opened in Visual Studio. /// </summary> /// <param name="filePath">Full Path of the file you are looking for.</param> /// <returns>The IVsTextView for this file if it is open. Returns null otherwise.</returns> private static IVsTextView GetIVsTextView(string filePath) { var sp = ShellUtils.GetGloblalServiceProvider(); IVsUIHierarchy uiHierarchy; uint itemID; IVsWindowFrame windowFrame; if (VsShellUtilities.IsDocumentOpen( sp, filePath, Guid.Empty, out uiHierarchy, out itemID, out windowFrame)) { // Get the IVsTextView from the windowFrame. return(VsShellUtilities.GetTextView(windowFrame)); } return(null); }