public static string GetParseableFileContent(string fileName) { IWorkbenchWindow window = FileService.GetOpenFile(fileName); if (window != null) { IViewContent viewContent = window.ViewContent; IEditable editable = viewContent as IEditable; if (editable != null) { return(editable.Text); } } //string res = project.GetParseableFileContent(fileName); //if (res != null) // return res; // load file Encoding tmp = DefaultFileEncoding; return(ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(fileName, ref tmp, tmp)); }
/// <summary> /// Gets the content of the file using encoding auto-detection (or DefaultFileEncoding, if that fails). /// If the file is already open, gets the text in the opened view content. /// </summary> public static string GetParseableFileContent(string fileName) { IViewContent viewContent = FileService.GetOpenFile(fileName); IEditable editable = viewContent as IEditable; if (editable != null) { return(editable.Text); } //string res = project.GetParseableFileContent(fileName); //if (res != null) // return res; OpenedFile file = FileService.GetOpenedFile(fileName); if (file != null) { IFileDocumentProvider p = file.CurrentView as IFileDocumentProvider; if (p != null) { IDocument document = p.GetDocumentForFile(file); if (document != null) { return(document.TextContent); } } using (Stream s = file.OpenRead()) { // load file Encoding encoding = DefaultFileEncoding; return(ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(s, ref encoding)); } } // load file return(ICSharpCode.TextEditor.Util.FileReader.ReadFileContent(fileName, DefaultFileEncoding)); }