Help!! How can i make a program that stops the program from append a new line in an existed file?
Code:
if (File.Exists(path))
{
}
FileStream fs = null;
if (!File.Exists(path))
{
using (fs = File.Create(path))
{
MessageBox.Show("Text File Created Succesfully!");
}
}
string[] OrigProductItems = { "Blood Pressure Monitor\t", "Digital Scale\t\t", "Footrest\t\t", "Health Care Thermometers", "Massager\t\t" };
int[] OrigProductQty = {30, 10, 5, 20, 10};
double[] OrigProductPrice = { 799.75, 499.75, 99.95, 79.75, 1990.75 };
if (File.Exists(path))
{
using (StreamWriter sw = File.AppendText(path))
{
for (ctrl = 0; ctrl < 5 ; ctrl++)
{
sw.WriteLine(OrigProductItems[ctrl] + "\t" + OrigProductQty[ctrl] + "\t\t" + OrigProductPrice[ctrl]);
}
}
}
}
just negate what you already have
if (!File.Exists(path)) // append only if file doesnt exist
{
using (StreamWriter sw = File.AppendText(path))
{
for (ctrl = 0; ctrl < 5 ; ctrl++)
{
sw.WriteLine(OrigProductItems[ctrl] + "\t" + OrigProductQty[ctrl] + "\t\t" + OrigProductPrice[ctrl]);
}
}
}