public void writeResults() { string dirPath = Path.GetDirectoryName(labelPath.Text); string fullPath = dirPath + "/rainfall2.txt"; File.WriteAllLines(fullPath, GoodNumbers.Select(x => string.Join("\n", x))); }
private void buttonUpload_Click(object sender, EventArgs e) { try { if (labelPath.Text == null) { MessageBox.Show("Open a valid document."); } else { //readingFile1(fileName); readingFile2(); // Positive Numbers int countGoodNumbers = GoodNumbers.Any() ? GoodNumbers.Count() : 0; textBoxGood.Text = countGoodNumbers.ToString(); // Negative Numbers int countBadNumbers = BadNumbers.Any() ? BadNumbers.Count() : 0; textBoxBad.Text = countBadNumbers.ToString(); // Count and display the rows textBoxTotalRows.Text = (countGoodNumbers + countBadNumbers).ToString(); // the min and max values found decimal minValue = GoodNumbers.Any() ? GoodNumbers.Min() : 0; textBoxMin.Text = minValue.ToString(); decimal maxValue = GoodNumbers.Any() ? GoodNumbers.Max() : 0; textBoxMax.Text = maxValue.ToString(); // and the average values decimal averageValue = GoodNumbers.Average(); textBoxAverage.Text = averageValue.ToString(); // create a second file names rainfall2.txt and will only have the values selected for processing writeResults(); } } catch (Exception ex) { MessageBox.Show(String.Format("Error: {0}", ex.Message)); } }