First off, don't try to save
anything in the root folder of any drive, and particularly not in the root of your boot drive: From Vista onwards it takes special permission to avoid virus tampering, and it will not get any easier.
Second, if this is really a ASP.NET application, you will almost certainly never get permission from your web host to access the true root directory, as this could cause huge problems with other sites if permission was given.
So get rid of this completely:
string dir = @"C:\Error.txt";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
And the rest of your code should work (but I'd use a folder away from my website root just to keep things tidy)