title: C# iTextSharp: The process cannot access the file because it is being used by another process
body: <p>I'm generating a pdf file from a template with iTextSharp, filling each field in this code portion:</p>
  
  <pre><code>        PdfReader pdfReader = new PdfReader(templatePath);
          try
          {
              using (FileStream newFileStream = new FileStream(newFilePath, FileMode.Create))
              {
                  using (PdfStamper stamper = new PdfStamper(pdfReader, newFileStream))
                  {
                      // fill each field
                      AcroFields pdfFormFields = stamper.AcroFields;
                      foreach (KeyValuePair&lt;string, string&gt; entry in content)
                      {
                          if (!String.IsNullOrEmpty(entry.Value))
                              pdfFormFields.SetField(entry.Key, entry.Value);
                      }
  
                      //The below will make sure the fields are not editable in
                      //the output PDF.
                      stamper.FormFlattening = true;
                      stamper.Close();
                  }                    
              }
          }
          finally
          {
              pdfReader.Close();
          }
  </code></pre>
  
  <p>Everything goes fine, file looks ok, but when i try to reopen the file to merge it with some other files I've generated in a unique document i get this error:</p>
  
  <pre><code>2015-11-23 09:46:54,651||ERROR|UrbeWeb|System.IO.IOException: The process cannot access the file 'D:\Sviluppo\communitygov\MaxiAnagrafeImmobiliare\MaxiAnagrafeImmobiliare\cache\IMU\E124\admin\Stampe\Provvedimento_00223850306_2015_11_23_094654.pdf' because it is being used by another process.
  </code></pre>
  
  <p>Error occurs at this point</p>
  
  <pre><code>foreach (Documento item in docs)
  {                                      
             string fileName = item.FilePath;
             pdfReader = new PdfReader(fileName); // IOException
             // some other operations ...                    
  }
  </code></pre>
  
  <p>Edit: Using Process monitor as suggested I can see there is no close CloseFile operation as I would expect. Can this be the source of the issue?</p>
  
  <p><a href="https://i.stack.imgur.com/XWTSd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XWTSd.png" alt=" "></a></p>
  
  <p>I've been stuck on this for hours any help is really really appreciated.</p>