Problem writing to a text file C#
<p>Here is my program:</p>

<pre><code>protected int CheckExisting(string item_id)
{
            StreamReader sr = new StreamReader(@"D:\ItemID.txt");
            string line = sr.ReadLine();

            while (line != null)
            {
                if (0 == string.Compare(line, item_id))
                    return 1;

                line = sr.ReadLine();
            }

            sr.Close();
            return 0;
}

protected void WriteNewLog(string item_id)
{
            using (StreamWriter sw = File.AppendText(@"D:\ItemID.txt"))
            {
                sw.WriteLine(item_id);
            }
}

protected void xHandler(int num)
{
    for(int i= 0; i&lt; num; i++)
        if (0 == CheckExisting(item_id))
        {                       
            WriteNewLog(item_id);
        }
}
</code></pre>

<p>When o run the program, an exception unhandled occur: <strong>"The process cannot access the file 'D:\ItemID.txt' because it is being used by another process."</strong> Can u guys help me fix that? Thanks so much!</p>
