C# Reading file in a directory
<p>I have an app that reads a CSV file called “words.csv”. My new requirement is that 1) it needs to ensure that there is only one CSV file in the directory before reading. 2) It should read any file with ".CSV" extension not just “words.csv” (after condition 1 is satisfied). Hope this makes sense?
Can anyone assist?</p>

<pre><code>public class VM
{
    public VM()
    {
        Words = LoadWords(fileList[0]);
    }

    public IEnumerable&lt;string&gt; Words { get; private set; }

    string[] fileList = Directory.GetFiles(@"Z:\My Documents\", "*.csv");


    private static IEnumerable&lt;string&gt; LoadWords(String fileList)
    {

        List&lt;String&gt; words = new List&lt;String&gt;();

        if (fileList.Length == 1)
        {

            try
            {
                foreach (String line in File.ReadAllLines(fileList))
                {
                    string[] rows = line.Split(',');

                    words.AddRange(rows);
                }

            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message);
            }

            return words;
        }
    }
}
</code></pre>
