title: File.WriteAllLines does not appear to be closing
body: <p>I am trying to add a feature to a website that will send an outlook invite attachment to email.  Everything runs the first time perfectly, but after running it again, I get the following error:  "The process cannot access the file 'OutlookCalendar.ics' because it is being used by another process."  I have searched high and low for an answer to this but it appears that when I use file.WriteAllLines, it doesn't close the file?  See code below...</p>
  
  <pre><code>     //CREATE OUTLOOK ATTACHMENT.....................................................................................................
          //..............................................................................................................................
          string schLocation = "Kettle Cuisine TBD";
          string schSubject = visitor + " is visiting.";
          string schDescription = other;
          System.DateTime schBeginDate = Convert.ToDateTime(date + " " + time);
          System.DateTime schEndDate = Convert.ToDateTime(date + " 17:00");
  
          //PUTTING THE MEETING DETAILS INTO AN ARRAY OF STRING
  
          String[] contents = { "BEGIN:VCALENDAR",
                            "PRODID:-//Flo Inc.//FloSoft//EN",
                            "BEGIN:VEVENT",
                            "DTSTART:" + schBeginDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), 
                            "DTEND:" + schEndDate.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), 
                            "LOCATION:" + schLocation, 
                       "DESCRIPTION;ENCODING=QUOTED-PRINTABLE:" + schDescription,
                            "SUMMARY:" + schSubject, "PRIORITY:3", 
                       "END:VEVENT", "END:VCALENDAR" };
  
          /*THE METHOD 'WriteAllLines' CREATES A FILE IN THE SPECIFIED PATH WITH 
         THE SPECIFIED NAME,WRITES THE ARRAY OF CONTENTS INTO THE FILE AND CLOSES THE
          FILE.SUPPOSE THE FILE ALREADY EXISTS IN THE SPECIFIED LOCATION,THE CONTENTS 
         IN THE FILE ARE OVERWRITTEN*/
  
          System.IO.File.WriteAllLines(Server.MapPath("OutlookCalendar.ics"), contents);
  
          //END CREATE OUTLOOK ATTACHMENT.....................................................................................................
          //..............................................................................................................................
  
  
          //Send out email
          Email.sendEmailOutlook(message, email, header);
  </code></pre>
  
  <p>In the email section I use this....
          //MAKE AN ATTACHMENT OUT OF THE .ICS FILE CREATED</p>
  
  <pre><code>        Attachment mailAttachment = new Attachment(System.Web.HttpContext.Current.Server.MapPath("OutlookCalendar.ics"));
          mail.Attachments.Add(mailAttachment);
  
          mail.IsBodyHtml = true;
          //Set email message and subjet
          mail.Subject = header;
          mail.Body = message;
  
          smtpClient.Send(mail);
  </code></pre>