2013-08-30 33 views
0

我有一個項目需要從我的表單打開一些pdf報告。由於該程序可以安裝在任何驅動器中,我使用winform位置目錄作爲我的路徑。我的報告位於名爲Reports的目錄中。它在開發中工作良好,因爲我的winform在bin \ debug下,但是當我部署我的解決方案並嘗試過程時,它不起作用,無法找到該文件。我在部署後創建了一個Reports目錄,但仍未找到我的pdf。如何打開位於winform項目中的文件

下面是代碼:

 'Open the requested file name. The files are stored in the 
    'same path as the main workbook. 
    '@param filename file to be opened 

    Function OpenReports(strFileName As String) As String 

     Dim reportFolder As String 

     Try 

      reportFolder = Path.Combine(Directory.GetCurrentDirectory(), "Reports") 
      System.Diagnostics.Process.Start(reportFolder & "\" & strFileName) 

     Catch ex As Exception 

      MsgBox("The " & strFileName & " is not found on directory") 

     End Try 

     Return strFileName 

    End Function 

Private Sub btnRptRangesToMarket_Click(sender As Object, e As EventArgs) Handles btnRptRangesToMarket.Click 

    'This procedure runs when the btnRptRangesToMarket is clicked 
    'the procedure opens the pdf below by running the OpenReports Function 

    OpenReports("Ranges to Market.pdf") 

End Sub 
+1

你在運行什麼操作系統,你可能會遇到UAC問題。我通常在ProgramData目錄中放置類似的信息,而不是應用程序目錄。 –

+0

@MarkHall我正在使用Windows 8 –

+0

*找不到文件。我在部署**後創建了Reports目錄**,但仍未找到我的pdf。(如何)您是否部署文件? – Chris

回答

2

嘗試Application.StartupPath而不是Directory.GetCurrentDirectory()。我總是用那個財產取得好成績。

這是從MSDN:

當前目錄是從原來的目錄,這是從該過程開始時的一個不同。

相關問題