2017-02-22 33 views
-1

我目前正試圖在Web瀏覽器中打開PDF文件。我從數據庫中檢索pdf的字節數組並將其存儲在應用程序文件夾中。從這裏我不能讓PDF在c#代碼中啓動。任何幫助將不勝感激,因爲我很難過。爲什麼不打開我的PDF文件。 ASP.net,c#

if(dt.Rows.Count > 0) 
     { 
      byte[] data = (byte[])dt.Rows[0][0]; 
      string strFileName = Utilities.GetAppBasePath()+Config.GetImages+DateTime.Now.Millisecond.ToString()+".pdf"; 
      System.IO.File.WriteAllBytes(strFileName, data); 

      OpenPDF(strFileName); 
} 
protected void OpenPDF(string strFileName) 
    { 
      Response.Redirect(strFileName); 
    } 
+1

'從這裏我不能得到PDF在c#代碼啓動。 ' - 你得到一個例外嗎?提供除「不起作用」之外的更多細節將會有所幫助。 –

回答

0

我不知道,如果運行的PDF很像運行正常的應用程序,如果是的話,那麼我認爲你最好的選擇可能是使用類似的Process.Start的「線(strFileName) ;」或'Process.Start(strFileName.Text);'

0

嗨,謝謝你的意見,非常感謝。有沒有例外,但它不起作用的原因是由於回傳電話。我現在已經爲此解決了這個問題。丹,你是對的它不可能通過響應這樣調用重定向並解決問題,我用下面的代碼:

if(dt.Rows.Count > 0) 
     { 
      byte[] data = (byte[])dt.Rows[0][0]; 

      OpenPDF(data);     
     } 

protected void OpenPDF(byte [] data) 
    { 
     HttpContext.Current.Response.Clear(); 
     HttpContext.Current.Response.ClearHeaders(); 
     HttpContext.Current.Response.ClearContent(); 
     HttpContext.Current.Response.ContentType = "application/pdf"; 
     HttpContext.Current.Response.Charset = ""; 
     HttpContext.Current.Response.AddHeader("Pragma", "public"); 
     HttpContext.Current.Response.AddHeader("Content-Disposition", "inline; filename=\"image.pdf\""); 
     HttpContext.Current.Response.BinaryWrite(data); 
     HttpContext.Current.Response.Flush(); 
     HttpContext.Current.Response.Close(); 
     HttpContext.Current.Response.End();    
    } 
再次

感謝您的幫助,表示歉意任何vauge的煩躁,即時通訊非常新張貼在這個網站上,我希望這篇文章可以幫助其他人解決這個問題。

謝謝

相關問題