title: giving error while creating pdf.The process cannot access the file.because it is being used by another process
body: <p>im exporting web page div into pdf and sending that mail to pdf. for first time its creating pdf and sending mail properly.but for next time its giving error saying . file is bieng used by a another process at this line</p>
  
  <pre><code> PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(strPath, FileMode.Create));
  </code></pre>
  
  <p>my aspx.cs code is-</p>
  
  <pre><code>System.IO.StringWriter stringWrite = new System.IO.StringWriter();
  
  
                  System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                  design.RenderControl(htmlWrite);
                  string myText = stringWrite.ToString().Replace("&amp;", "&amp;amp;");
                  StringReader sr = new StringReader(myText.ToString());
                  Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
  
                  string strPath = Request.PhysicalApplicationPath + "\\Temp\\WeeklyReport of " + Projname + ".pdf";
                  PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(strPath, FileMode.Create));
                  pdfDoc.Open();
                  XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr);
  
                  pdfDoc.Close();
                  pdfDoc.Dispose();
  
                  LblNoteMsg.Text = strPath;
                  DateTime input = DateTime.Now;
                  int delta = DayOfWeek.Monday - input.DayOfWeek;
                  DateTime dats = DateTime.Now.AddDays(delta);
                  //this week
                  DateTime monday = input.AddDays(delta);
                  string MonDate = monday.ToShortDateString();
                  DateTime sat = monday.AddDays(5);
                  string SatDate = sat.ToShortDateString();
                  StreamReader r = new StreamReader(Server.MapPath("~/WeeklyMail.txt"));
                  string body = r.ReadToEnd();
                  MailMessage Msg = new MailMessage();
                  string MailId = txtMailId.Text;
                  foreach (string ss in MailId.Split(",".ToCharArray()))
                  {
                      if (string.IsNullOrEmpty(ss) == false)
                      {
                          Msg.To.Add(new MailAddress(ss));
                      }
                  }
  
  
                  Msg.Subject = "Weekly status Report";
                  Msg.Body = body;
                  Msg.IsBodyHtml = true;
                  Msg.Attachments.Add(new Attachment(strPath));
  
                  SmtpClient MailServer = new SmtpClient();
                  try
                  {
  
                      MailServer.Send(Msg);
  </code></pre>