I currently have two different event handlers in C#, which perform two different functions. Although how could I combine the two methods together, so only 1 button could perform both actions? (Taking into account that button1_Click event must be performed first.)
private void button2_Click(object sender, EventArgs e)
{
var file = File.AppendText(@"c:\output2.txt");
foreach (string tmpLine in File.ReadAllLines(@"c:\output.txt"))
{
if (File.Exists(tmpLine))
{
file.WriteLine(tmpLine);
}
}
file.Close();
}
private void button1_Click(object sender, EventArgs e)
{
using (StreamWriter sw = File.AppendText(@"c:\output.txt"))
{
StreamReader sr = new StreamReader(@"c:\filename.txt");
string myString = "";
while (!sr.EndOfStream)
{
myString = sr.ReadLine();
int index = myString.LastIndexOf(":");
if (index > 0)
myString = myString.Substring(0, index);
sw.WriteLine(myString);
}
button2_Click(sender, e);
}
}