Server.MapPath: xxxx is a physical path but a virtual path was expected. ASP.Net

Last Reply on Jul 17, 2012 02:55 AM By Mudassar

Posted on Jul 17, 2012 02:50 AM

i used this code ... it is giving this error

C:/Users/Administrator/Documents/Visual Studio 2010/Projects/WebApplication1/WebApplication1/CrystalReport3.rpt' is a physical path, but a virtual path was expected.

 

    protected void Page_Load(object sender, EventArgs e) 
    {
 ConnectionInfo ConnInfo = new ConnectionInfo();
 ConnInfo.DatabaseName = "newMreport";
 ConnInfo.UserID = "sa";
 ConnInfo.Password = "123456789";
 ConnInfo.IntegratedSecurity = true;
 protected void Button3_Click(object sender, EventArgs e) {
 DataSet1 dsReport = new DataSet1();
 con = new SqlConnection("Data Source=TRAINING-ROOM-8;Initial Catalog=newMreport;Integrated Security=True;User ID=sa;Password=123456789;");
 con.Open();
 string strSelect = "SELECT * FROM Transactions";
 ConnectionInfo ConnInfo = new ConnectionInfo();
 ConnInfo.DatabaseName = "newMreport";
 ConnInfo.UserID = "sa";
 ConnInfo.Password = "123456789";
 ConnInfo.IntegratedSecurity = true;
 SqlCommand cmd = new SqlCommand(strSelect, con);
 SqlDataAdapter dAdapter = new SqlDataAdapter(cmd);
 dAdapter.Fill(dsReport.Tables["Transactions"]);
 con.Close();
 ReportDocument crystalReport = new ReportDocument();
 crystalReport.Load(Server.MapPath("C:/Users/Administrator/Documents/Visual Studio 2010/Projects/WebApplication1/WebApplication1/CrystalReport3.rpt"));
 crystalReport.SetDataSource(dsReport);
 CrystalReportViewer1.ReportSource = crystalReport;
 CrystalReportViewer1.DataBind();
 CrystalReportViewer1.RefreshReport();
 }

 

Posted on Jul 17, 2012 02:55 AM

change

crystalReport.Load(Server.MapPath("C:/Users/Administrator/Documents/Visual Studio 2010/Projects/WebApplication1/WebApplication1/CrystalReport3.rpt"));

to

crystalReport.Load(Server.MapPath("~/CrystalReport3.rpt"));