locked
Crystal Report Print Option -VB.NET RRS feed

  • Question

  • User-1578974752 posted

    My project is in vb.net .I have a  crystal report,Once I click save button,the report is saved to the folder (where the path is specified).
    How can I print the Crystal report directly when i click the save button.Appreciate the help

    Tuesday, January 8, 2019 9:58 AM

Answers

  • User-893317190 posted

    Hi shsu,

    If you want to show the pdf  which is in server side, you could use a iframe. Please set the src to the path of your pdf.

    If you want to click a button to pop up the pdf. You could use bootstrap.

    Below is my code.

      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    </head>
    <body>
        <form id="form1" runat="server">
              
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
      Launch demo modal
    </button>
    
    
          <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
             <iframe src="../rep.pdf" height="1000" width="500">
    
        </iframe>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>
            <script src="../Scripts/jquery-3.3.1.js"></script>
       <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
        </form>
    </body>
    </html>
    

    The result.

    For more information about bootstrap modal , please refer to

    https://getbootstrap.com/docs/4.2/components/modal/

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 11, 2019 9:53 AM

All replies

  • User-893317190 posted

    Hi shsu,

    ReportDocument has a method PrintToPrinter to print the report.

     Dim cryRpt As ReportDocument = New ReportDocument()
            cryRpt.Load(Server.MapPath("~/extraConrols/CrystalReport1.rpt"))
           
          
            CrystalReportViewer1.RefreshReport()
            CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf
     
    
            cryRpt.PrintToPrinter(1, False, 0, 0)

    You could also use  <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" /> to print.

    aspx 

       <form id="form1" runat="server">
            <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
        </form>

    Code behind.

      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim cryRpt As ReportDocument = New ReportDocument()
            cryRpt.Load(Server.MapPath("~/extraConrols/CrystalReport1.rpt"))
            CrystalReportViewer1.ReportSource = cryRpt
           
    
            CrystalReportViewer1.RefreshReport()
            CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf

    The result.

    For more way to print , please refer to https://stackoverflow.com/questions/29486992/print-crystal-report-directly-in-asp-net-c-sharp

    Best regards,

    Ackerly Xu

    Wednesday, January 9, 2019 3:22 AM
  • User-1578974752 posted

    Crystal report viewer is no there for the reports.it will directly save to the path. It is saving in to the folder .so how can I allow user to open that report from that folder.  Thanks

    Friday, January 11, 2019 8:11 AM
  • User-893317190 posted

    Hi shsu,

    Where is your folder? Is it in your project( which means it is in server side)? Or it is downloaded by the user and saved to its own computer?

    If it is the second case,server could not operate folder in client side.

    If it is the first case , it makes no sense to open a folder in server side,because your project runs in different computer.

    So , I am not clear what you want to do and which folder you mean.

    Could you show the code you have tried?

    Best regards,

    Ackerly Xu

    Friday, January 11, 2019 8:30 AM
  • User-1578974752 posted

    pdf is saving in a folder in the server under (wwwroot). so when user click a button I want the pdf to be open. My project is in the server itself.  I placed a button and in its click event done the below code

    Dim filePath As String = Path.GetFileName("C:\inetpub\wwwroot\ABCD\ABCD\Reports\Slip")

    Response.WriteFile(filePath)

     

    Response.End()

    Friday, January 11, 2019 8:37 AM
  • User-893317190 posted

    Hi shsu,

    If you want to show the pdf  which is in server side, you could use a iframe. Please set the src to the path of your pdf.

    If you want to click a button to pop up the pdf. You could use bootstrap.

    Below is my code.

      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
    </head>
    <body>
        <form id="form1" runat="server">
              
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
      Launch demo modal
    </button>
    
    
          <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
             <iframe src="../rep.pdf" height="1000" width="500">
    
        </iframe>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Save changes</button>
          </div>
        </div>
      </div>
    </div>
            <script src="../Scripts/jquery-3.3.1.js"></script>
       <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
        </form>
    </body>
    </html>
    

    The result.

    For more information about bootstrap modal , please refer to

    https://getbootstrap.com/docs/4.2/components/modal/

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 11, 2019 9:53 AM
  • User1341756031 posted
    • Add crystal report (.cr) file to your ASP.NET application.
    • Add a report instance on the page level.

    Dim report As MyReport = New MyReport

    Populate reports data on Page_Init

    ' Get data in a DataSet or DataTable
    Dim ds As DataSet = GetData()
    ' Fill report with the data
    report.SetDataSource(ds)

    • Print Report

    report.PrintToPrinter(1, False, 0, 0)

    More on....Vb.Net Crystal Reports

    Thursday, March 21, 2019 5:07 AM