0

i spend a lot of time to resolve this problem but to working. I use server.mapPath function to specific valid path file. why only local machine is working but not working in production because i this (server.mapPath) is a great function

c#

[WebMethod]
public string getDocument(string id, string location)
{
  ReportDocument report = new ReportDocument();
  report.Load(Server.MapPath("~/Reports/report1.rpt"));
  Stream stream = report.ExportToStream(ExportFormatType.PortableDocFormat);
  MemoryStream streamReader = new MemoryStream();

  stream.CopyTo(streamReader);

  return Convert.ToBase64String(streamReader.ToArray());
}

ajax

function printPreview(reqID) {                        
            var base_url = "/Webservice/webService.asmx/getDocument";
            $.ajax({
                type: "POST",
                url: base_url,
                data: "{'id': " + reqID + ", 'location':'" + objUser.location + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    console.log(response.d)
                },
                error: function (response) {
                    alert(response.d);
                }
            });

Check API backend Look like the problem happen when ReportDocument.Load because i test in production with File.Exists function without ReportDocument.Load and the result return file is exist but cannot load why ? Have any one else know this ?

error exception

Could not load file or assembly 'CrystalDecisions.CrystalReports.Engine, Version=13.0.3500.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot find the file specified.

I'm add bindingRedirect from 13.0.2000.0 -> 13.0.3500.0 in web.config and still not working. I'm see in server production C:/Windows/assembly all of (CrystalDecisions.Shared, CrystalDecisions.CrystalReports.Engine, CrystalDecisions.ReportSource) is version 13.0.2000.0 but why another project is working. Please help me, thank you so much.

Ragnarok M
  • 21
  • 1
  • 6

2 Answers2

0

Try without the tilde and forward slash character.

report.Load(Server.MapPath("Reports/report1.rpt"));

This expects report (.rpt file) to be available in 'Reports' subfolder of your application root folder

mdowes
  • 592
  • 7
  • 18
  • i use ~/ for start with the root of path folder then go to Reports folder because my service.asmx file is inside another folder. – Ragnarok M Jan 22 '19 at 08:16
  • Crystal report tries to create a temporary file in **C:\Windows\temp** folder before reading or writing files. Make sure the permission is there. I would also suggest changing the identity of the application pool to currently logged in user. Basically, you have to do a trial and error method to resolve this. – mdowes Jan 23 '19 at 04:29
  • other project that i make in the same server not have a problem. I'm use log4net to log error and i add all assembly that show in error but still error (Invalid report file path) but it go through if file.Exists(same path). it make me confused. – Ragnarok M Jan 23 '19 at 16:54
  • Loading a crystal report in a web application is not straight forward as loading a file, it does various tricks under the hood. Can you try using an absolute path to the report file? – mdowes Jan 24 '19 at 05:02
0

You could use System.IO Path.Combine. There you just add your Foldernames and your Filename and get a correctly formatted Path. Could look something like that:

string sPath = Path.Combine(@"\\" + "Reports", "report1.rpt");

You can add string variables (Foldernames) with just a comma.

MaxW
  • 421
  • 1
  • 7
  • 22
  • Please see more information that i'm edit. i test file exist with out crystalDocument.load and it return true (that file is exist) – Ragnarok M Jan 23 '19 at 02:14