Utwórz plik, jeśli plik nie istnieje

Muszę odczytać mój kod, jeśli plik nie istnieje, stworzyć inny dopisać. W tej chwili czyta, jeśli istnieje, tworzy i dołącza. Oto kod:

<code>if (File.Exists(path))
{
    using (StreamWriter sw = File.CreateText(path))
    {
</code>

Czy zrobiłbym to?

<code>if (! File.Exists(path))
{
    using (StreamWriter sw = File.CreateText(path))
    {
</code>

Edytować:

<code>string path = txtFilePath.Text;

if (!File.Exists(path))
{
    using (StreamWriter sw = File.CreateText(path))
    {
        foreach (var line in employeeList.Items)
        {
            sw.WriteLine(((Employee)line).FirstName);
            sw.WriteLine(((Employee)line).LastName);
            sw.WriteLine(((Employee)line).JobTitle);
        }
    }
}
else
{
    StreamWriter sw = File.AppendText(path);

    foreach (var line in employeeList.Items)
    {
        sw.WriteLine(((Employee)line).FirstName);
        sw.WriteLine(((Employee)line).LastName);
        sw.WriteLine(((Employee)line).JobTitle);
    }
    sw.Close();
}
</code>

}

questionAnswers(5)

yourAnswerToTheQuestion