2016-04-22 29 views
0

我用Abcpdf,Abcpdf HttpContent.Create FileNotFoundException異常在ASP.net MVC方面,但文件中存在

有時候我在生產FileNotFoundException異常與路徑使用創建HttpMultipartMimeForm後由HttpContent.Create(梅索德

的主要部分這個時間碼效果很好

的PDF是在上下文中科瑞其中

  1. ASP.NET網站A被稱爲
  2. 呼叫網站B生成PDF
  3. 網站B調用B上的網址爲HTML to PDF abcpdf方法。
  4. 後以前的要求,以B爲終點,網站一經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; 
    } 
+0

你的例外是很清楚,你是在 – jamiedanq

+0

但經過我看生產服務器上的文件搜索目錄中的文件通過步入它存在 – ArDumez

+0

調試代碼,並檢查目錄路徑甚至是正確的 – jamiedanq

回答

0

檢查權限在PDF文件和目錄上,檢查文件是否附有一些「區域」信息。

+0

是的,但這段代碼是時間的主要部分,所以這不是一個權限問題,我認爲... – ArDumez

相關問題