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

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"));

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.

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.

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/)

Related

File or directory not found although it exists and the path is correct

I have a problem - I cannot find my file when I open it using http://localhost:49652/.well-known/acme-challenge/FfI7Xeq7_QH5R5pCd3LhAkU4k3nOqBz9mNbvJ9EwMoQ although it exists and the path is correct.
I use ASP.NET C#, OS: Windows Server 2012 And IIS 8.0.
And error:
Help me... Please!
I want to forward you to an other question: What file extensions are blocked by default in IIS
The issue is that IIS has a configuration, how to handle requested files.
Depending on the extension, there have to be done different actions: While resources like .txt or .jpg files are just sent into the network as they are stored on the disk, other files like .aspx or .asmx have to be parsed, executed in dotnet and then the output have to be sent etc.
Other extensions like .dll or .exe are blocked by default, I think.
The problem is, that your files do not have any extension, so for this directory you have to configure that IIS should pass through all of the files.
Found another usefull link to microsoft: https://learn.microsoft.com/en-us/iis/configuration/system.webserver/security/requestfiltering/fileextensions/

C# get current directory without having to specify full path? [duplicate]

We have a web application written in ASP.NET 3.5. In it, we access a file in the code-behind. (Ordinary C# file access, done on the server during the page life-cycle, this has nothing to do with URLs or web browsers).
On our production systems, we specify the full path to the file in question in the web.config. We'd like to be able to include a local copy of the file in the project in version control, and then to use a relative path in the version-controlled web.config to point to it, so that a checked-out copy of the application could be run from within Visual Studio's debugger without having to do any configuration.
The problem is that when the web application is running in debug mode, its working directory is neither the project nor the solution directory. In a windows or console application, in a project's properties page I can set the working directory. But in a web application I cannot.
Any ideas on how I can manage to make this work?
To get the path of the root of the application:
//equivalent to Server.MapPath("/"); if at domain root, e.g Http://mysite.com/
string path = Server.MapPath("~");
This answer gives a rundown of a few different common Server.MapPath() uses that may also be of use to you.
In code behind: HttpContext.Current.Server.MapPath("~")
Use:
Server.MapPath("~");

Change download folder [duplicate]

I am trying to create new file in visual studio 2012
fileStream = new FileStream("google_com.txt", FileMode.CreateNew);
But i keep getting this error
Access to the path 'C:\Program Files (x86)\IIS Express\google_com.txt' is denied.
Plz help to fix this poblem.
Solutions:
Put a specific location for google_com.txt file. like C:\google_com.txt. Actually it is not allowing to create the file in default location(inside program files) as it might not have the proper privilege.
If you want to create the file in default location(inside program files) run Visual Studio as Administrator.(R-Click-> Run as Administrator).
Run Visual Studio as Administrator
You can't write to the Program Files folders on Windows Vista or later unless you're running elevated/as an administrator.
You should be writing to the application's App_Data folder if you need to write anywhere. Look into using Server.MapPath().
If this is in a web app, the file will be created in the application's root, which in this case is your iis express directory. Run Visual Studio as Administrator, or change the location of the file by specifying an explicit path.
Official Microsoft response:
Issue occurs because of missing permissions on a local resource that
the ASP.NET application tries to access If you are unable to get a
clear description of the problem because of a custom error message,
run FileMon and reproduce the problem. Stop and save the capture as
FileMon.xls and open the file in Microsoft Excel. On the Data menu,
click Filter, and then click AutoFilter to use the filtering
capabilities of Excel. Now select the drop-down list in column F and
look for "ACCESS DENIED" errors.
A sample FileMon output is shown below. 10381 1:01:11 PM w3wp.exe:2320
OPEN C:\winnt\microsoft.net\framework\v1.1.4322\Temporary ASP.NET
Files\sessiontest\8832e585\275ec327\global.asax.xml ACCESS DENIED NT
AUTHORITY\NETWORK SERVICE As you can see from the filtered results,
we have narrowed down the cause of the problem. FileMon shows that the
NT AUTHORITY\NETWORK SERVICE account is missing NTFS permissions on
the C:\Winnt\Microsoft.net\Framework\v1.1.4322\Temporary ASP.NET Files
folder. This should be straight forward to fix. For more information
about using FileMon to troubleshoot ASP.NET, click the following
article number to view the article in the Microsoft Knowledge Base
https://support.microsoft.com/es-ve/help/910449/troubleshooting-common-permissions-and-security-related-issues-in-asp
Try this:
Server.MapPath("~/ FolderName / google_com.txt ")

Could not write to output file -- Access is denied

I recently switched computers and copied all my projects over to my new local drive. I reformatted the computer I'm on now so it was pretty much a clean machine. Everything seemed to be working fine, but when I opened one of my projects that I had been running from my old machine, it would no longer compile, and I get the following error message:
Could not write to output file 'c:\Users\user\Documents\Projects\RegressionWeb\OnetouchUpload\obj\debug\OneTouchUpload.dll' -- 'Access is denied.'
I'm getting an error like that for each project I have in my solution. I'm also getting this error:
Unexpected error creating debug information file 'c:\Users\user\documents\projects\RegressionWeb\RegressionWeb\obj\Debug\RegressionWeb.PDB' Access is denied
I've searched high and low, and the only similar issues I could find online related specifically to ASP.NET and IIS, neither of which has anything to do with my project (My projects are class libraries of mostly NUnit tests with some support classes).
I am the administrator on my local machine. I have already taken ownership of every file in the project using takeown /f .\RegressionWeb /r /d y and also tried to ensure that nothing had a status of Read-only, but the following file threw an error when I tried changing the read-only property of it's parent folder:
An error occurred applying attributes to the file:
C:...\Regressionweb.sln.DotSettings.user
Access is denied
Basically this project was working perfectly and had no errors from my old computer. After copying over everything, this DotSettings.user file will not be modified, and Visual Studio can't write to any of the dll files. I'm sure the answer must lie in a Visual Studio setting somewhere. Any and all suggestions would be greatly appreciated.
I think Karl has it right. I had a similar situation once, and what I did was delete the file in question, clean the solution, and then rebuild. If the project needs that file it should recreate it; in my case it didn't need it because it never recreated it, but the project ran just fine.
One other thing I would recommend; you may be selecting the read-only attribute of the parent folder off and selecting this setting to recurse through all sub-folders and files, but that doesn't mean that's what's happening. For all your sub-folders and files (especially the ones that are cropping up as errors) inspect each one individually and make sure the read-only attribute is off.
My money is on your files are read-only. Verify they are read-only and change them or add your files to a source control system and let them get handled by that.
I was able to get this working by closing Visual Studio and then opening it again, but being careful to run Visual Studio "As Administrator". To do this, from the Start menu, right click on Visual Studio and choose "Run as Administrator".
it seems that the same error is sometimes displayed when the app pool user doesn't have access to the %TMP%/%TEMP% folder.
You'll need to grant IIS_IUSRS read and modify access over the temp folder of the user the app pool is running as.
This could either be the temp folder in the app pool user's profile, e.g. c:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp, or the system temp folder at c:\windows\temp.
See if it is related to this:Could not write to output file - Access is denied
. That would be a bit of a bugger to track down. In this case the project is self-referencing the dll and preventing access to the file.
This has a very simple solution, you just have to make sure that your directory name(folder name) is not the same as your file name. I created a folder by the name Pointers, my code was in a file pointers.cpp. When I compiled the code it kept showing the same error. I just had to change the directory or folder name to L1_pointers. You can change it to anything you want and it worked.

File.Copy fails when copying a DLL that is not in use

I've built a winforms app (C#) that will take a list of file paths, and copy those files (from a different VS solution) to a new location (In a folder the user specifies) in the same directory structure they currently exist on local file system.
I use the Path class, Directory class etc and everything works wonderfully...except when it reaches a file path that points to a DLL.
The DLLs I am trying to copy are a part of the other solution, and that solution is not currently open.
I have tried restarting computer to make sure visual studio isn't somehow hooking into that DLL even after the solution is closed.
The DLL in question can be copied by regular manual means (i.e. copy and paste shortcut).
So short of creating a batch file in the program, and running xcopy on that DLL path, I don't know of a way to get this to work.
From what I have found from google searches (which isn't much on this particular situation), File.Copy() should work..
Any help would be wonderful, even if it is a link to a duplicate question I may have over looked.
Thanks!
-The error message is: The process cannot access the file [insert file path] because it is being used by another process (The path is definitely correct also)
-Just downloaded and tried to search for the DLL name with Process Explorer.. I also ran a similar exe from command prompt to no avail. It claims nothing is using it. That's why I am utterly baffled by this. Also, I just checked the permissions and everything looks great (i.e. Full Control, owner effective permissions)
-It does not handle open files. It basically build the correct src and dest paths and does a File.Copy() on those. How would I go about handling open files? I'm sure I could figure out if it was open, but what would I do it it were open?
It is not complaining about the file you're trying to copy, it is complaining about the file that you're trying to overwrite with the copy. Lots of candidates for that, virus scanners always get very excited about new DLLs, for example. Or it is loaded into a process, the typical failure mode for trying to implement your own auto-updater.
You can rename the target file to make your copy succeed.
Are you in vista or win7? If so, Check your 'User Account Control Settings'. Sometimes this can interfere with .NET security options and prevent file operations that would otherwise work.
As well as Process Explorer, I would use Process Monitor also from Microsoft so you can see what is happening at the point of failure and allows you to see if anything else is accessing the dll.
Possible culprits are
the program you are running,
your antivirus package
a virus.
If the path it is complaining about is the destination path, then is is possible that the path is too long?
Also, when using Process Explorer, make sure you have enabled the option to show details for all processes and not just your own.
I just ran into this issue as well. I tried copying a .DLL from an FTP server to a local directory (replacing the existing one) and for the life of me I could not get it to work. Keeps giving me an 'Access Denied code: 5' Error.
I then realized that the .DLL on the FTP server was not marked as hidden while the .DLL I was trying to replace was marked as hidden.
Once I changed the local one to also be visible. I had no more issues.
So my solution is:
Make sure both files are visible.
Hope this helps someone

Categories

Resources