Q:

Keeping an open StreamWriter as Class Field

I was trying to write a class that would keep an open StreamWriter until the instantiated object was destroyed -- this is to avoid the normal using idiom, because it's important that outside sources do not edit the file while the program is running (hence FileShare.Read).  
Once instantiated, the file is created successfully via the constructor.  Calls to the Write method do not actually write anything and throw no exceptions.  Once the object is destroyed, the destructor throws an exception on the sw.Close() of Cannot access a closed file., even though the BaseStream isn't null.  I'm not sure I understand the reasoning for that.
This question follows somewhat similar approach, but in some other type of class.  So I thought this approach should have worked, but wasn't able to determine why it isn't.
class SchemaWriter
{
    private StreamWriter sw;
    private string path;

    /// <summary>
    /// Creates an object to handle writing Schema.ini information
    /// </summary>
    /// <param name="Path">Path to place Schema.ini file in</param>
    public SchemaWriter(string Path)
    {
        path = Path;
        sw = new StreamWriter(File.Open(Path + "Schema.ini", FileMode.Create,
                              FileAccess.ReadWrite, FileShare.Read));
    }

    /// <summary>
    /// Writes Schema information about the supplied file name
    /// </summary>
    /// <param name="FileName">Name of file to write the Schema info about</param>
    public void Write(string FileName)
    {
        sw.WriteLine(String.Format(@"[{0}]", FileName));
        sw.WriteLine(@"Format=TabDelimited");
        sw.WriteLine();
    }

    /// <summary>
    /// Closes StreamWriter, deletes ini file
    /// </summary>
    ~SchemaWriter()
    {
        if(sw.BaseStream != null)
            sw.Close();
        File.Delete(path + @"Schema.ini");
    }
}

A:

The GC has already claimed it (and disposed of it).
The only thing you should do is to implement IDisposable. Do the following:
class SchemaWriter : IDisposable
{
    private StreamWriter sw;

    public void Dispose()
    {
       sw.Dispose();
    }

    ...
}

You can now use your object with:
using(var writer = new SchemaWriter())
{
}

This will close your StreamWriter immediately when you are done with the object. And if you don't use the using the GC will collect the StreamWriter for you when it feels like it.

