Managing list files in C#
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.
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;
}
}
}

