繁体   English   中英

在ASP.NET MVC上下文中Abcpdf HttpContent.Create FileNotFoundException但文件存在

[英]Abcpdf HttpContent.Create FileNotFoundException in ASP.net mvc context but file exist

我使用Abcpdf,

有时在创建HttpMultipartMimeForm之后,当HttpContent.Create(方法使用路径使用

此代码大部分时间都运行良好

PDF是在上下文中创建的

  1. 称为ASP.NET网站A
  2. 呼叫网站B以生成PDF
  3. 网站B在B上针对HTML到PDF abcpdf方法的调用网址。
  4. 对B的先前请求完成后,网站A通过HttpClient HttpMultipartMimeForm将文件发送到服务器C有时会引发异常,但是当我在服务器上查看文件时,该文件存在

A和B在同一台计算机上,并且共享相同的目录。

我以为我尝试访问该文件时文件还没有写完。 但是如何解决呢?

谢谢。

1.服务器A

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

2.服务器B

theDoc.Save(HostingEnvironment.ApplicationPhysicalPath + "/xxx/" + ".pdf");
theDoc.Clear();

3.服务器A

 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;
  }

检查PDF文件和目录的权限,检查文件没有附加“区域”信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM