I am using Visual Studio 2010
with Crystal Report
. It is working fine in my local server but on web server, it is giving error : System.Runtime.InteropServices.COMException: Invalid file name
.
I tried many solutions like put .rpt
file in any folder and provide that path, give full permission to windows temp folder, enable parent path form IIS etc.
But none of them is working. Please help me to solve this.
My current path :
crystalReport.Load(Server.MapPath("~/PurchaseOrder1.rpt"));
3 Answers
Answers 1
Not a whole answer but I'm too new to SO just to comment. One thing you could try is to download Process Monitor and watch to see where Crystal is trying to load the file from and that may help. Process Monitor will give a lot of output but that can be filtered on, for instance, part of the filename. It may tell you if there is a permissions issue too. I find it very useful for these sort of situations where you can't work out why a file is not found.
Answers 2
My guess is that the culprit may be a trailing /
on the Webserver path.
Try using Path.Combine(Server.MapPath("~"), "PurchaseOrder1.rpt");
This should put appropriate /
in the path and might fix your issue.
Answers 3
I think that the main difference with local and server environment is IIS root and the virtual directory that your application is located.
I mean, if the file is in the root of the site, you might want to use
crystalReport.Load(Server.MapPath("/PurchaseOrder1.rpt"));
OR you can try putting the rpt file into the same folder with ViewPurchaseOrder.aspx
without changing the code
If it doesn't work, if you could share paths (both physical and virtual) we can check further.
*Edit: When using Server.MapPath
/
returns site root
~/
returns root directory of the application
The difference is that if your site is:
http://yoursite.com And you have an application that's on wwwroot\somedir\app
So in your "app" (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 comments:
Post a Comment