.Net & Crystal Reports lost pdf file

693 views Asked by At

I'm working on an application developed in C # with VS 2003 (Framework 1.1), and Crystal Reports for Visual Studio .NET. This application make invoices and prints them in PDF format.

By doing this there is no exception, but in the development environtment, the file does not exist physically, I can't find it. In production environment, work without problems: the file exists in the specified path.

The main difference is the machine where the application is running. The development machine is virtual (Hyper-V Version: 6.2.9200.16384) with Windows XP SP3 2002 version that runs on Windows 8 Pro. The development is done in the virtual machine. The production machine is Windows XP SP3 2002.

I already tried:

  • Change the user identified in the machine.
  • Change the export format to doc, xls, and always with the same result in both environments.
  • Change the path where the file is recorded, avoiding using "My Documents".
  • Googling.

The application code is:

// (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 ();

     That's all and runs without exceptions in both cases.

As I said the only problem is that in my development environment file is not created, and in productive machine the file is ok.

I make the release and install de application from de development machine to the production machine.

As the application works in the production environment nobody cares this much in the business . I'm interested particularly because I developed.

Of course, thank you very much.

1

There are 1 answers

0
Abdulrahman_88 On

first you need to add radio buttons as follow:

      <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>

in your code at bind report add :

           If rblFormat.SelectedValue = 1 Then
                cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")
            ElseIf rblFormat.SelectedValue = 2 Then
                cryRpt.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, True, "ExportedReport")
            ElseIf rblFormat.SelectedValue = 3 Then
              ExportDataSetToExcel(DT, "ExportedReport")
            End If

For Excel add:

        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