These are some quick and dirty functions for loading and saving list files in C#. They pretty much suppress all exceptions and won’t give much indication of failure other than SaveList returning false or LoadList returning an empty result set.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace XeonProductions { class Utils { public static bool SaveList(string path, List<string> inputList, bool append) { bool result = false; try { using (StreamWriter streamWriter = new StreamWriter(path, append)) { foreach (string s in inputList) streamWriter.WriteLine(s); result = true; } } catch { } return result; } public static List<String> LoadList(string path) { List<string> resultList = new List<string>(); try { using (StreamReader streamReader = new StreamReader(path)) { string line; while ((line = streamReader.ReadLine()) != null) { resultList.Add(line); } } } catch { } return resultList; } } } |