Abcpdf HttpContent.Create FileNotFoundException in ASP.net mvc context but file exist
<p>I use Abcpdf, </p>

<p>Sometimes I get in production FileNotFoundException after creation of HttpMultipartMimeForm with path use by the <code>HttpContent.Create(</code> methode</p>

<p>The major part of time this code works well</p>

<p>The PDF is creat in context where </p>

<ol>
<li>ASP.NET website A is called</li>
<li>A call website B to generate the PDF </li>
<li>Website B call url on B for HTML to PDF abcpdf method.</li>
<li>After previous request to B is finish, website A send file to server C via HttpClient HttpMultipartMimeForm and Exception is throw sometimes, but when I look on the server the file exist</li>
</ol>

<p>A and B is on the same machine and sharing the same directories.</p>

<p>I supposed that the file is not finish to write on disk when I try to acces on it. But how to resolved this ?</p>

<p>Thanks.</p>

<p><strong>1. Server A</strong></p>

<pre><code>using (HttpClient pdfClient = new HttpClient("http://" + ConfigurationManager.AppSettings["xxx"]))
{
    using (HttpResponseMessage message = pdfClient.Get(UrlDictionary.callxxx(xxxID, xxxID)))
    {
        message.EnsureStatusIsSuccessful();
        message.Content.ReadAsStream();
    }
}
</code></pre>

<p><strong>2. Server B</strong></p>

<pre><code>theDoc.Save(HostingEnvironment.ApplicationPhysicalPath + "/xxx/" + ".pdf");
theDoc.Clear();
</code></pre>

<p><strong>3. Server A</strong></p>

<pre><code> HttpMultipartMimeForm request = new HttpMultipartMimeForm();

  FileInfo info = new FileInfo(pathFile);
  HttpFormFile file = new HttpFormFile();
  file.Content = **HttpContent.Create(info, "multipart/form-data")**; (Exception FileNotFoundException)
  file.FileName = info.Name;
  file.Name = "file";


  request.Files.Add(file);
  request.Add("id", id);

  using (HttpResponseMessage response = client.Post(
      string.Format("/xxx/{0}", id), 
      request.CreateHttpContent()))
  {
      ExceptionIfBadRequest(response);
      Contrat contrat = (Contrat)FromXml(response.Content.ReadAsString(), typeof(Contrat));
      return contrat;
  }
</code></pre>