Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I am unsure why I am getting this error "Invalid report file path"
Image: Click me to view image of error


I am 100% sure that the report is in the correct path, I even tried to put the entire path (e.g. C:\Users\IAmTheUser\Desktop\MyProject\Reports\MyReport.rpt

What I have tried:

C#
ReportDocument rptDoc = new ReportDocument();
       string strRptLoad = Server.MapPath("../Reports/MyReport.rpt");
       rptDoc.Load(strRptLoad);
       //rptDoc.Load("C:\\Users\\IAmTheUser\\Desktop\\MyProject\\Reports\\MyReport.rpt");

       DataSetPrintAll.spSelectReimbursePrintAllDataTable dt = new DataSetPrintAll.spSelectReimbursePrintAllDataTable();
       dtPrintAllAdapter printAdapter = new dtPrintAllAdapter();

       dt = printAdapter.GetData(transactionNo);
       DataSet ds = new DataSet();
       ds.Tables.Add(dt);

       rptDoc.SetDataSource(ds);
       crPrint.ReportSource = rptDoc;
       crPrint.DataBind();
       crPrint.DocumentView = CrystalDecisions.Shared.DocumentViewType.PrintLayout;
       crPrint.Dispose();
Posted
Updated 3-Nov-16 17:10pm
v2
Comments
Afzaal Ahmad Zeeshan 3-Nov-16 19:38pm    
Are you sure those folders also exist? The problem can be caused if a folder is missing.
bjay tiamsic 3-Nov-16 19:54pm    
Yeah. It is included in my project.
[no name] 3-Nov-16 19:42pm    
Web servers generally do not have access to the entire file system.
bjay tiamsic 3-Nov-16 19:55pm    
Hi. I am still working locally. I tried debugging in my application server and other computers and I got the same error.
[no name] 4-Nov-16 8:10am    
Nothing you said changes anything. You are working locally on a WEB SERVER.

1 solution

Try the following;

C#
string strRptLoad = Server.MapPath("/Reports/MyReport.rpt"); //remove double dots ..


Generally when you specify Server.MapPath - it gives you the root of the application directory and then follow the folders inside.
You can use Server.MapPath from within any pages - does not matter whether those pages are within sub directories in the application or not - It will give you the root of the application directory and then you would have to guide through inner folders as in the example.

Hope this helps and don't forget to mark this as a solution if it works..

Cheers
 
Share this answer
 
v3
Comments
bjay tiamsic 4-Nov-16 1:10am    
Isn't it that the dots indicate to move one folder out? I tried your suggestion but it game me this error
System.InvalidOperationException: Failed to map the path '/Reports/MyReport.rpt'.

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