Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi Mate

I am creating a report using CrystalDecisions and its throwning an exception on the Load method.

What I have tried:

<
C#
pre lang="c#"><pre>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult AdvertReport(FormCollection fc)
        {
            DataSet ds = obIlReports.Generate_AdvertDetailsReport();
            ds.Tables[0].TableName = "DtTest";

            if(ds.Tables[0].Rows.Count > 0)
            {
                ReportClass rptH = new ReportClass();
                rptH.FileName = Server.MapPath("-/Reports/AdvertReport.rpt");
                rptH.Load();
                rptH.SetDataSource(ds.Tables[0]);
                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();


                Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                stream.Seek(0, SeekOrigin.Begin);
                return File(stream, "application/pdf", "AdvertReport.pdf");
            }
            return View();
        }
    }


public class ReportsMaster : IlReports
   {
       public DataSet Generate_AdvertDetailsReport()
       {
           using(SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["eNtsaOnlineRegistrationDB"].ToString()))
           {
               con.Open();
               DataSet ds = new DataSet();

               // Handling Exception
               try
               {
                   SqlCommand cmd = new SqlCommand("GetAdvertReport", con);
                   cmd.CommandType = CommandType.StoredProcedure;
                   SqlDataAdapter da = new SqlDataAdapter();
                   da.SelectCommand = cmd;
                   da.Fill(ds);

                   if(ds.Tables.Count > 0)
                   {
                       return ds;
                   }
                   else
                   {
                       return ds = null;
                   }

               }
               catch(Exception )
               {
                   throw;
               }
               finally
               {
                   ds.Dispose();
               }
           }
       }
   }


<connectionStrings>
    <add name="eNtsaOnlineRegistrationDB" connectionString="Data Source=GcobaniM-L\SQLEXPRESS; DataBase=eNtsaOnlineRegistrationDB; Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>
Posted
Updated 18-Feb-20 3:35am
v2
Comments
Richard Deeming 18-Feb-20 14:39pm    
So which are we to believe?

How to work with crystaldecision in ASP.NET MVC for report as file format?[^]
"yes i did debugg more than 10 times there are no error"

Or:
"its throwning an exception on the Load method"


If it's the latter, then you need to provide the full details of the exception.

You also need to delete your previous - and now inaccurate - copy of this question.

1 solution

Long, long shot, but I think you have a hyphen (-) where you need a tilde (~):
C#
rptH.FileName = Server.MapPath("~/Reports/AdvertReport.rpt");
 
Share this answer
 
Comments
gcogco10 18-Feb-20 9:36am    
My keyboard does not use that hyphen i tried using several times, its only - not ~ on VS 2019
phil.o 18-Feb-20 9:42am    
If you do not want to use a tilde, then try to specify an absolute full path to the resource.
gcogco10 18-Feb-20 9:46am    
But phil this got nothing to do with path, im checking other things like my connectionString. Because at first had an issue with attached not being wanted to load. Here is my connectionString. <connectionstrings>
<add name="eNtsaOnlineRegistrationDB" connectionstring="Data Source=GcobaniM-L\SQLEXPRESS; DataBase=eNtsaOnlineRegistrationDB; Integrated Security=True" providername="System.Data.SqlClient">
phil.o 18-Feb-20 9:54am    
Well, like I said, it's a long shot. You did not provide which exception you get, its message nor its stack trace. So it's just a wild guessing game.
Please edit your question and provide informations about this exception.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900