private void WriteNationsToFile(string fileName, List <Nation> nations, out string formattedText) { // Get the text NationsExporter.ExportToCsvFile(nations, out formattedText); // open the write stream using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.UTF8)) { // loop through the lines of text using (StringReader reader = new StringReader(formattedText)) { string line; while ((line = reader.ReadLine()) != null) { // write the line sw.WriteLine(line); } } // tidy up sw.Close(); } }
public ExportText GetExportNationsCsvText(string userId) { ExportText exportText = new ExportText { Format = "text/plain" }; User foundUser = _userDatabase.LoadedItems.FirstOrDefault(x => x.Id.ToString() == userId); if (foundUser == null) { return(exportText); } GeographyProvider geographyProvider; BooksReadProvider booksReadProvider; _books = new ObservableCollection <Book>(); if (GetProviders(out geographyProvider, out booksReadProvider)) { if (geographyProvider.Nations != null && geographyProvider.Nations.Any()) { List <Nation> nations = geographyProvider.Nations.OrderBy(x => x.Name).ToList(); // Get the file export string string formattedText; NationsExporter.ExportToCsvFile(nations, out formattedText); // Return the formatted text exportText.FormattedText = formattedText; } } return(exportText); }