C# .Net&;水晶报告丢失pdf文件

C# .Net&;水晶报告丢失pdf文件,c#,.net,pdf,crystal-reports,windows-xp-sp3,C#,.net,Pdf,Crystal Reports,Windows Xp Sp3,我正在使用VS2003(Framework 1.1)和VisualStudio.NET的Crystal Reports开发一个用C#开发的应用程序。 此应用程序生成发票并以PDF格式打印 这样做也不例外,但在开发环境中,文件在物理上不存在,我找不到它。在生产环境中,无问题工作:文件存在于指定路径中 主要区别在于运行应用程序的机器。 开发计算机是虚拟的(Hyper-V版本:6.2.9200.16384),具有在Windows 8 Pro上运行的Windows XP SP3 2002版本。开发是在虚

我正在使用VS2003(Framework 1.1)和VisualStudio.NET的Crystal Reports开发一个用C#开发的应用程序。 此应用程序生成发票并以PDF格式打印

这样做也不例外,但在开发环境中,文件在物理上不存在,我找不到它。在生产环境中,无问题工作:文件存在于指定路径中

主要区别在于运行应用程序的机器。 开发计算机是虚拟的(Hyper-V版本:6.2.9200.16384),具有在Windows 8 Pro上运行的Windows XP SP3 2002版本。开发是在虚拟机中完成的。 生产机器是Windows XP SP3 2002

我已经试过了:

  • 更改机器中标识的用户。
  • 将导出格式更改为doc、xls,并在两种环境中始终使用相同的结果。
  • 更改记录文件的路径,避免使用“我的文档”。
  • 谷歌搜索。
申请代码为:

// (Guarantee that all variables have the right type, are initialized and have a consistent value. txtDesde and txtHasta are textboxs)
    string strFile = "myfile.pdf";
    string strDirectory = @"myFolder\";
    string strSubDirectory = @"MySubFolder\";
    
    if (!System.IO.Directory.Exists(strDirectory))
    {
        System.IO.Directory.CreateDirectory(strDirectory);
    }

    strDirectory + = strSubDirectory;
    if (!System.IO.Directory.Exists(strDirectory))
    {
        System.IO.Directory.CreateDirectory(strDirectory);
    }
    
    ReportClass a = new myCrystalReport(); // It is an existing Crystal Report and in an appropriate format
    a.ResourceName = "myCrystalReport.rpt";
    a.SetDataSource (myDataSet); //myDataSet is a System.Data.DataSet, loaded with the necessary and consistent data
    DiskFileDestinationOptions dfdo = new DiskFileDestinationOptions();
    dfdo.DiskFileName = strDirectory + strfile;
    a.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
    a.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
    a.ExportOptions.DestinationOptions = dfdo;

    //-> the next two lines have the same result
    //a.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, strDirectory + strfile); 
    a.Export ();

    a.Dispose ();
仅此而已,在这两种情况下都会毫无例外地运行

正如我所说的,唯一的问题是,在我的开发环境中,没有创建文件,而在生产机器中,文件是可以的

我将de应用程序从de开发机器发布并安装到生产机器

由于应用程序是在生产环境中工作的,所以在业务中没有人这么关心它。我特别感兴趣,因为我发展了


当然,非常感谢。

首先,您需要添加单选按钮,如下所示:

      <tr>
          <td>
          </td>
          <td>
          <asp:RadioButtonList ID="rblFormat" runat="server" RepeatDirection="Horizontal" CssClass="Profiletitletxt">
          <asp:ListItem Text="PDF" Value="1" Selected="True"></asp:ListItem>
          <asp:ListItem Text="MS Word" Value="2"></asp:ListItem>
          <asp:ListItem Text="MS Excel" Value="3"></asp:ListItem>
          </asp:RadioButtonList>

          </td>
          <td>
          </td>
          </tr>
对于Excel添加:

        Public Shared Sub ExportDataSetToExcel(ByVal ds As DataTable, ByVal filename As String)
        Dim response As HttpResponse = HttpContext.Current.Response
        response.Clear()
        response.Buffer = True
        response.Charset = ""
        response.ContentType = "application/vnd.ms-excel"
            Using sw As New StringWriter()
            Using htw As New HtmlTextWriter(sw)
                Dim dg As New DataGrid()
                dg.DataSource = ds
                dg.DataBind()
                dg.RenderControl(htw)
                response.Charset = "UTF-8"
                response.ContentEncoding = System.Text.Encoding.UTF8
                response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble())
                response.Output.Write(sw.ToString())
                response.[End]()
            End Using
        End Using
    End Sub

你有没有试过单步通过代码。。?您还检查了程序集版本或dll以及.net framework是否在所有计算机上都相同吗。。?还有,为什么不在代码中添加一些错误检查和异常处理。。?另外,将代码包装在using(){}周围,这样您就不必手动调用a.Dispose()@DJKRAZE,谢谢。我已经毫无例外地一步一步地运行了代码。已检查程序集、DLL和框架版本是否正确。这段代码包含在try…catch中。根据你的建议,我尝试了一个使用块,但没有改变。
        Public Shared Sub ExportDataSetToExcel(ByVal ds As DataTable, ByVal filename As String)
        Dim response As HttpResponse = HttpContext.Current.Response
        response.Clear()
        response.Buffer = True
        response.Charset = ""
        response.ContentType = "application/vnd.ms-excel"
            Using sw As New StringWriter()
            Using htw As New HtmlTextWriter(sw)
                Dim dg As New DataGrid()
                dg.DataSource = ds
                dg.DataBind()
                dg.RenderControl(htw)
                response.Charset = "UTF-8"
                response.ContentEncoding = System.Text.Encoding.UTF8
                response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble())
                response.Output.Write(sw.ToString())
                response.[End]()
            End Using
        End Using
    End Sub