Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何打开winform项目中的文件_Vb.net_Winforms - Fatal编程技术网

Vb.net 如何打开winform项目中的文件

Vb.net 如何打开winform项目中的文件,vb.net,winforms,Vb.net,Winforms,我有一个项目,需要从我的表格中打开一些pdf报告。由于该程序可以安装在任何驱动器中,因此我使用winform位置目录作为路径。I报告位于名为“报告”的目录中。它在开发中运行良好,因为winform处于bin\debug下,但当我部署解决方案并尝试该过程时,它不起作用,无法找到文件。我在部署后创建了一个报告目录,但仍然没有找到我的pdf 代码如下: 'Open the requested file name. The files are stored in the 'sam

我有一个项目,需要从我的表格中打开一些pdf报告。由于该程序可以安装在任何驱动器中,因此我使用winform位置目录作为路径。I报告位于名为“报告”的目录中。它在开发中运行良好,因为winform处于bin\debug下,但当我部署解决方案并尝试该过程时,它不起作用,无法找到文件。我在部署后创建了一个报告目录,但仍然没有找到我的pdf

代码如下:

        '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

尝试
Application.StartupPath
而不是
Directory.GetCurrentDirectory()
。我总是能得到很好的结果

这来自MSDN:


当前目录与启动进程的原始目录不同

您运行的是什么操作系统,可能会遇到UAC问题。我通常将类似信息放在ProgramData目录中,而不是应用程序目录中。@MarkHall我使用的是Windows 8,找不到该文件。我在部署后创建了一个报告目录,但仍然没有找到我的pdf。(如何)部署文件???@Chris我创建了Reports文件夹,并将该文件夹放在应用程序目录下