Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 474.4k

How to get URL for your crystalreport download?

Aug 6 2020 10:58 AM
Hi Team
 
How do get URL for your download button if you have Homecontroller? I have created View but i want that download but within my form. Example is below;
  1. // HomeController  
  2.   //GET/Download_Report  
  3.   
  4.         public ActionResult Download_ExcelReport()  
  5.         {  
  6.             //var _db = new eNtsaRegistration();  
  7.   
  8.             var data = (from q in db.eNtsaRegForms select new {   
  9.             Id = q.Id,  
  10.             Title = q.Title,  
  11.             FirstName = q.FirstName,  
  12.             LastName = q.LastName,  
  13.             Position =q.Position,  
  14.             Company = q.Company,  
  15.             StreetAddress = q.StreetAddress,  
  16.             StreetAddressLine = q.StreetAddressLine,  
  17.             City = q.City,  
  18.             StateProvince = q.StateProvince,  
  19.             ZipCode = q.ZipCode,  
  20.             Email = q.Email,  
  21.             CellNumber = q.CellNumber,  
  22.             Country = q.Country,  
  23.             DietaryRequirements = q.DietaryRequirements  
  24.               
  25.               
  26.             }).ToList();  
  27.   
  28.             ReportDocument rpt = new ReportDocument();  
  29.             rpt.Load(Server.MapPath("~/Reports/TrainingAcademy.rpt"));  
  30.             rpt.SetDataSource(data);  
  31.            // rpt.Refresh();  
  32.              
  33.   
  34.   
  35.             Response.Buffer = false;  
  36.             Response.ClearContent();  
  37.             Response.ClearHeaders();  
  38.   
  39.             try  
  40.             {  
  41.                 Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);  
  42.                 stream.Seek(0, SeekOrigin.Begin);  
  43.                 return File(stream, "application/vnd.ms-excel""eNtsaRegistrationForm.xls");  
  44.             }  
  45.             catch  
  46.             {  
  47.                 throw;  
  48.                 return View();  
  49.             }  
  50.   
  51.              
  52.         }  
  53.   
  54. // View of Download_XMLReport  
  55. @model eNtsaRegistrationTraining.Models.RegViewAndRoleViewModel  
  56.   
  57. @{  
  58.     ViewBag.Title = "Download_ExcelReport";  
  59. }  
  60.   
  61. <h2>Download_ExcelReport</h2>  
  62.   
  63. @using (Html.BeginForm())   
  64. {  
  65.     @Html.AntiForgeryToken()  
  66.       
  67.     <div class="form-horizontal">  
  68.           
  69.         <hr />  
  70.         @Html.ValidationSummary(true""new { @class = "text-danger" })  
  71.         <div class="form-group">  
  72.             <div class="col-md-offset-2 col-md-10">  
  73.                 <input type="submit" value="Create" class="btn btn-default" />  
  74.             </div>  
  75.         </div>  
  76.     </div>  
  77. }  
  78.   
  79. <div>  
  80.     @Html.ActionLink("Back to List""RegFormSave")  
  81. </div>  
  82.   
  83. // View Form  
  84. @model eNtsaRegistrationTraining.Models.RegViewAndRoleViewModel  
  85.   
  86. @{  
  87.     ViewBag.Title = "SubmitRegDetails";  
  88.     List<SelectListItem> CountryLIstData = new List<SelectListItem>();  
  89.     foreach (var data in Model.CountryLIst)  
  90.     {  
  91.         SelectListItem selectList = new SelectListItem();  
  92.         selectList.Text = data.Text;  
  93.         selectList.Value = data.Value;  
  94.         CountryLIstData.Add(selectList);  
  95.     }  
  96. }  
  97. @if(User.IsInRole("SuperAdmin")) {   
  98.     <center>  
  99.         <div class="z-inex" style="width:1000px;">  
  100.             <div class="register-logo">  
  101.   
  102.             </div>  
  103.             <div class="card">  
  104.                 <div class="card-body register-card-body">  
  105.                     <center>  
  106.                         <img src="~/Images/eNtsa.png" />  
  107.                     </center>  
  108.                     <center>  
  109.                         <h1>  
  110.                             <p><b>Training Course Registration:Motion MasterClass</b></p>  
  111.                         </h1>  
  112.                         <hr />  
  113.                         <p>Course date: 25-27 February 2020</p>  
  114.                         <hr />  
  115.                         <p>  
  116.                             Note:Please note your registration is submit approval as seats for this course is limited. Once your registration is confirmed, you will receive a quote for subject to your confirmation  
  117.                             followed by an invoice.  
  118.                         </p>  
  119.                     </center>  
  120.   
  121.   
  122.                     <center>  
  123.                         @using (Html.BeginForm("SubmitRegDetails""Home", FormMethod.Post))  
  124.                         {  
  125.   
  126.   
  127.                         <div class="form-horizontal">  
  128.   
  129.                             <hr />  
  130.   
  131.                             <div class="form-group row">  
  132.                                 <label for="Title" class="col-sm-2 col-form-label">Title</label>  
  133.                                 <div class="col-sm-3 ">  
  134.                                     @Html.EditorFor(model => model.RegForm.Title, new { htmlAttributes = new { @class = "form-control" } })  
  135.                                     @Html.ValidationMessageFor(model => model.RegForm.Title, ""new { @class = "text-danger" })  
  136.   
  137.                                 </div>  
  138.                             </div>  
  139.   
  140.                             <div class="form-group row">  
  141.                                 <label for="Name" class="col-sm-2 col-form-label">Name:</label>  
  142.                                 <div class="col-sm-3 ">  
  143.                                     @Html.EditorFor(model => model.RegForm.FirstName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Name" } })  
  144.                                     @Html.ValidationMessageFor(model => model.RegForm.FirstName, ""new { @class = "text-danger" })  
  145.   
  146.                                 </div>  
  147.   
  148.                                 <div class="col-sm-3">  
  149.                                     @Html.EditorFor(model => model.RegForm.LastName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "LastName" } })  
  150.                                     @Html.ValidationMessageFor(model => model.RegForm.LastName, ""new { @class = "text-danger" })  
  151.                                 </div>  
  152.                             </div>  
  153.   
  154.                             <div class="form-group row">  
  155.                                 <label for="Position" class="col-sm-2 col-form-label">Position:</label>  
  156.                                 <div class="col-sm-3">  
  157.                                     @Html.EditorFor(model => model.RegForm.Position, new { htmlAttributes = new { @class = "form-control" } })  
  158.                                     @Html.ValidationMessageFor(model => model.RegForm.Position, ""new { @class = "text-danger" })  
  159.                                 </div>  
  160.                             </div>  
  161.   
  162.                             <div class="form-group row">  
  163.                                 <label for="Company" class="col-sm-2 col-form-label">Company:</label>  
  164.                                 <div class="col-md-3">  
  165.                                     @Html.EditorFor(model => model.RegForm.Company, new { htmlAttributes = new { @class = "form-control" } })  
  166.                                     @Html.ValidationMessageFor(model => model.RegForm.Company, ""new { @class = "text-danger" })  
  167.                                 </div>  
  168.                             </div>  
  169.   
  170.                             <div class="form-group row">  
  171.                                 <label for="Addresss" class="col-sm-2 col-form-label">Address*</label>  
  172.                                 <div class="col-sm-5">  
  173.                                     @Html.EditorFor(model => model.RegForm.StreetAddress, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Street Address" } })  
  174.                                     @Html.ValidationMessageFor(model => model.RegForm.StreetAddress, ""new { @class = "text-danger" })  
  175.                                 </div>  
  176.                             </div>  
  177.                             <div class="form-group row">  
  178.                                 <label for="Address" class="col-sm-2 col-form-label"></label>  
  179.                                 <div class="col-sm-5">  
  180.                                     @Html.EditorFor(model => model.RegForm.StreetAddressLine, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Street Address Line 2" } })  
  181.                                     @Html.ValidationMessageFor(model => model.RegForm.StreetAddressLine, ""new { @class = "text-danger" })  
  182.                                 </div>  
  183.                             </div>  
  184.                             <div class="form-group row">  
  185.                                 <label for="City" class="col-sm-2 col-form-label"></label>  
  186.                                 <div class="col-sm-3">  
  187.                                     @Html.EditorFor(model => model.RegForm.City, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "City" } })  
  188.                                     @Html.ValidationMessageFor(model => model.RegForm.City, ""new { @class = "text-danger" })  
  189.                                 </div>  
  190.                                 <label for="State/Province" class="col-form-label"></label>  
  191.                                 <div class="col-sm-3">  
  192.                                     @Html.EditorFor(model => model.RegForm.StateProvince, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "State/Province" } })  
  193.                                     @Html.ValidationMessageFor(model => model.RegForm.StateProvince, ""new { @class = "text-danger" })  
  194.                                 </div>  
  195.   
  196.                             </div>  
  197.                             <div class="form-group row">  
  198.                                 <label for="ZipCode" class="col-sm-2 col-form-label"></label>  
  199.                                 <div class="col-sm-3">  
  200.                                     @Html.EditorFor(model => model.RegForm.ZipCode, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "ZipCode", id = "textZipCode" } })  
  201.                                     @Html.ValidationMessageFor(model => model.RegForm.ZipCode, ""new { @class = "text-danger" })  
  202.                                 </div>  
  203.                                 @using (Html.BeginForm("Index""Home", FormMethod.Post))  
  204.                                 {  
  205.                                     <div class="col-sm-3">  
  206.                                         @Html.DropDownListFor(model => model.RegForm.Country, CountryLIstData as List<SelectListItem>)  
  207.                                     </div>  
  208.                                 }  
  209.   
  210.                             </div>  
  211.   
  212.                             <div class="form-group row">  
  213.                                 <label for="Email" class="col-sm-2 col-form-label">Email:</label>  
  214.   
  215.                                 <div class="col-sm-4">  
  216.                                     @Html.EditorFor(model => model.RegForm.Email, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Email", id = "textEmail" } })  
  217.                                     @Html.ValidationMessageFor(model => model.RegForm.Email, ""new { @class = "text-danger" })  
  218.                                 </div>  
  219.                                 <label id="labelMessage_email" class="text-danger" style="display:none">This field is required</label>  
  220.                             </div>  
  221.   
  222.                             <div class="form-group row">  
  223.                                 <label for="Attendee" class="col-sm-2 col-form-label">Attendee Cell Number*</label>  
  224.                                 <div class="col-sm-3">  
  225.                                     @Html.EditorFor(model => model.RegForm.CellNumber, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Cell Number", id = "textCellNumber" } })  
  226.                                     @Html.ValidationMessageFor(model => model.RegForm.CellNumber)  
  227.                                 </div>  
  228.   
  229.                             </div>  
  230.   
  231.                             <div class="form-group row">  
  232.                                 <label for="Verify not a human" class="col-sm-2 col-form-label">Please verify you not a human*</label>  
  233.                                 <div class="col-sm-3">  
  234.                                     @using (Html.BeginForm("FormSubmit""GetCapatcha", FormMethod.Post))  
  235.                                     {  
  236.                                         <div class="g-recaptcha" data-sitekey="6LcLN6cZAAAAABbgHtWziQB9nsWNXqZcpBnLU6dd">  
  237.   
  238.                                         </div>  
  239.                                     }  
  240.                                 </div>  
  241.                             </div>  
  242.   
  243.                             <div class="form-group row">  
  244.                                 <label class="col-sm-2 col-form-label">Dietary requirements:</label>  
  245.                                 <div class="col-sm-3">  
  246.                                     <div class="form-check">  
  247.                                         @Html.CheckBoxFor(model => model.DietMain.None, new { @class = "form-check-input" })  
  248.                                         <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.None)">None</label>  
  249.                                     </div>  
  250.                                     <div class="form-check">  
  251.                                         @Html.CheckBoxFor(model => model.DietMain.Vegetarian, new { @class = "form-check-input" })  
  252.                                         <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.Vegetarian)">Vegetarian</label>  
  253.                                     </div>  
  254.   
  255.                                     <div class="form-check">  
  256.                                         @Html.CheckBoxFor(model => model.DietMain.Vegan, new { @class = "form-check-input" })  
  257.                                         <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.Vegan)">Vegan</label>  
  258.                                     </div>  
  259.   
  260.                                     <div class="form-check">  
  261.                                         @Html.CheckBoxFor(model => model.DietMain.Halaal, new { @class = "form-check-input" })  
  262.                                         <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.Halaal)">Halaal</label>  
  263.                                     </div>  
  264.   
  265.                                     <div class="form-check">  
  266.                                         @Html.CheckBoxFor(model => model.DietMain.Other, new { @class = "form-check-input" })  
  267.                                         <label class="form-check-label" for="@Html.IdFor(m => m.DietMain.Other)">Other</label>  
  268.                                     </div>  
  269.   
  270.                                 </div>  
  271.                             </div>  
  272.   
  273.                             <div class="form-group">  
  274.                                 <div class="col-md-offset-2 col-md-10">  
  275.                                     <input type="submit" value="Submit" class="btn btn-primary" />  
  276.                                 </div>  
  277.   
  278.                             </div>  
  279.                             <div class="form-group">  
  280.                                 <div class="col-md-offset-2 col-md-10">  
  281.                                     <input type="submit" value="Download" class="btn btn-danger" />  
  282.                                 </div>  
  283.                             </div>  
  284.                         </div>  
  285.   
  286.   
  287.   
  288.                         }  
  289.                         <div>  
  290.                             @Html.ActionLink("Back to list""SaveRegForm")  
  291.                         </div>  
  292.                     </center>  
  293.                     </center>  
  294.                     }  
  295.                     <span style="font-size:20px;margin:20px;padding:20px;border:1px; solid#ff0000">  
  296.                         @ViewData["Message"]  
  297.                     </span>  
  298.                     <script src='https://www.google.com/recaptcha/api.js' type="text/javascript"></script>  
  299.   
  300.                     <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
  301.   
  302.   
  303.   
  304.                     <!--Handling form-validation when empty-->  
  305.                     <script type='text/javascript'>  
  306.                         $(function () {  
  307.                             //When the blur event occurs from your Textbox (you lose focus)  
  308.                             $('#textEmail').blur(function () {  
  309.                                 var email = document.getElementById("textEmail").value;  
  310.                                 var expr = /[a-z0-9._%+-]+[a-z0-9.-]+\.[a-z]{2,}$/;  
  311.                                 if (!expr.test(email)) {  
  312.                                     document.getElementById("labelMessage_email").style.display = "inline";  
  313.                                 }  
  314.                                 else {  
  315.                                     document.getElementById("labelMessage_email").style.display = "none";  
  316.                                 }  
  317.                             });  
  318.                         });  
  319.   
  320.                         // Error message for cell-phone.  
  321.                         $(function () {  
  322.                             $('#textCellNumber').blur(function () {  
  323.                                 var cell = document.getElementById("textCellNumber").value;  
  324.                                 var expr = /[a-z0-9._%+-]+[a-z0-9.-]+\.[a-z]{2,}$/;  
  325.                                 if (!expr.test(cell)) {  
  326.                                     document.getElementById("labelMessage_cell").style.display = "inline";  
  327.                                 } else {  
  328.                                     document.getElementById("labelMessage_cell").style.display = "none";  
  329.                                 }  
  330.                             });  
  331.   
  332.                         });  
  333.   
  334.   
  335.                         // Error message for ZipCode.  
  336.                         $(function () {  
  337.                             $('#textZipCode').blur(function () {  
  338.                                 var zipcode = document.getElementById("textZipCode").value;  
  339.                                 var expr = /[a-z0-9._%+-]+[a-z0-9.-]+\.[a-z]{2,}$/;  
  340.                                 if (!expr.test(zipcode)) {  
  341.                                     document.getElementById("labelMessage_zip").style.display = "inline";  
  342.                                 } else {  
  343.                                     document.getElementById("labelMessage_zip").style.display = "none";  
  344.                                 }  
  345.                             });  
  346.                         });  
  347.                     </script>  
  348.                      
 

Answers (1)