public class Processor { public void ProcessFile(string FilePath) { string FileContent = null; if(ReadAllContent(FilePath,out FileContent)){ Console.WriteLine(FileContent); } else { Console.WriteLine(string.Format("Ошибка: {0}", FileContent)); } } public bool ReadAllContent(string Path, out string text) { text = null; if(string.IsNullOrEmpty(Path)) { text = "Отсутствует путь к файлу."; return false; } FileInfo fileInfo = new FileInfo(Path); if(!fileInfo.Exists) { text = "Файл с заданным именем не существует."; return false; } // Здесь так же написал вариант с оптимизацией чтениея объёмного файла, что не обязательно, если не стоит таких задач. if(fileInfo.Length < Int32.MaxValue) { try{ using(FileStream fs = fileInfo.Open(FileMode.OpenOrCreate, FileAccess.Read, FileShare.None)) using(BufferedStream bs = new BufferedStream(fs, Convert.ToInt32(fileInfo.Length))) using (StreamReader sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { text+=line; } } } catch(Exception ex){ text = ex.Message; return false; } } else { try{ using(StreamReader sr = fileInfo.OpenText()) { string line; while ((line = sr.ReadLine()) != null) { text+=line; } } } catch(Exception ex){ text = ex.Message; return false; } } return true; } }