System.Runtime.InteropServices.COMException: Invalid file name in Crystal Report

I am using Visual Studio 2010 with Crystal Report . It works fine on my local server, but on the web server it gives an error: System.Runtime.InteropServices.COMException: Invalid file name .

I tried many solutions, such as put .rpt file in any folder and provided this path, gave full permission to the temporary Windows folder, included the parent IIS path, etc.

But none of them work. Please help me solve this problem.

My current path:

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


Crystal Report Error

+5
source share
3 answers

Not the complete answer, but I'm too new to SO to just comment. One thing you could try is to download the Process Monitor and see where Crystal is trying to download the file, and that might help. Process Monitor will give many results, but can be filtered, for example, in the file name part. He can tell you if there is a problem with permissions. I find this very useful for situations where you cannot understand why the file was not found.

+2
source

My assumption is that the culprit may be the final / on the way to the web server.

Try using Path.Combine(Server.MapPath("~"), "PurchaseOrder1.rpt");

This should put the appropriate / in the path and may fix your problem.

0
source

I think the main difference from the local and server environment is the IIS root and the virtual directory where your application is located.

I mean, if the file is in the root of the site, you can use

crystalReport.Load(Server.MapPath("/PurchaseOrder1.rpt"));

OR you can try to put the rpt file in the same folder using ViewPurchaseOrder.aspx without changing the code

If this does not work, if you can share the paths (both physical and virtual), we can additionally check.

* Edit: when using Server.MapPath

/ returns the root of the site

~/ returns the root directory of the application

The difference is that if your site:

http://yoursite.com And you have an application that is on wwwroot\somedir\app

So, in your β€œapplication” ( http://yoursite.com/somedir/app )

/ should return the root of the site ( http://yoursite.com )

~ / should return the root of the application ( http://yoursite.com/somedir/ )

0
source

Source: https://habr.com/ru/post/1247585/


All Articles