I am using the following code to attempt to print a PDF file using Spire PDF.
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
doc.LoadFromFile(monroneyFilename);
doc.PrinterName = monroneyPrinter;
lock (printLock)
{
doc.PrintDocument.Print();
}
When it gets to the LoadFromFile method, it gives me a File doesn't exist exception. The rest of the code doesn't execute.
The monroneyFilename is "p:\foldername\11111111111111111.pdf" where the ones are 17 characters representing a Vehicle Identification Number.
There are no spaces in the filename or folder name, so the other answers I've seen about this do not apply.
I'm running this from within an ASP.NET Web Service.
Anyone have any ideas?
I was able to discover the problem. The P: drive was mapped to a folder on a network PC on a VPN on the server. I was crossing domains, so the user for the AppPool of the web service was not able to access the files on the remote server. I was able to copy the PDF locally and access it that way to test and it worked fine.
It seems Spire does not give exceptions for bad credentials, it just tells you the file doesn't exist.
Related
We're running into a very strange problem on one of our reporting servers (running Crystal Reports for .Net 4 in IIS on a Windows 2008 server). When trying to run a report, we get an error saying "Load Report Failed", with an InnerException of "Invalid file name". This just started a few months ago, and had been working fine for years previously.
I have checked online and all the suggestions that I can find have been tried to no avail. A few notes about this issue:
Everything I can find on the Internet indicates this is a problem generating the temp report file. We have changed the registry setting TemDir to point to a different location than the standard temp directory.
We can see that the temporary .rpt files are being created in the desired directory, even when we get the error. I pulled one down locally and it opens in Crystal Reports designer with the data I would have expected.
We are not trying to export the reports to any file format, we are just using the standard report renderer.
This is only happening in one environment. When we copied the code that works in our higher environment Crystal server, we still get the same error.
Our server management team assures us no server changes have happened just prior to the issue (though I'm not sure we can prove that definitively).
Some fixes I have tried (not necessarily in this order):
Giving the account that the Website uses read/write access to the root of C:
Adding the account that the Website uses to the Administrators local group
Removing, then re-adding read/write/execute permissions to the temporary report directory. (Same results as above - temp files are created but we get the error still.)
Giving the account that the Website uses access to C:\Windows\Temp (no reason why that should matter since we are specifying the temp directory but thought I would give it a whirl anyway)
Stopped/started IIS, the application pool, rebooted the server.
Does anyone have any other suggestions we can look at for this problem? My gut tells me that there's still some lingering permissions issue but I can't find it.
As requested, here is some code where the error occurs:
Private Sub OpenReportFile()
Dim reportPath As String = System.Configuration.ConfigurationManager.AppSettings("ReportFileLocation")
If _reportDefinition Is Nothing Then Exit Sub
_theReport = New CrystalDecisions.CrystalReports.Engine.ReportDocument
_theReport.Load(reportPath & _reportDefinition.ReportFilePath, OpenReportMethod.OpenReportByTempCopy)
End Sub
The error is thrown on _theReport.Load.
AppSettings("ReportFileLocation") contains the base folder (a local path on the D drive) where the .rpt files reside.
_reportDefinition is a local domain object that contains the specific report path.
When the two are combined, the value of reportPath would be a local path like "D:\Inet\docroot\WebCrystal\Reports\MyReportFile.rpt"
This issue happens for every report.
i'm trying to open launch Excel specifing an existing file to open. This is my code:
Protected Sub fileManager_SelectedFileOpened(source As Object, e As FileManagerFileOpenedEventArgs)
Try
Dim FullName As String = e.File.FullName
System.Diagnostics.Process.Start(FullName)
dvFileError.Visible = False
Catch ex As Exception
dvFileError.Visible = True
lblFileError.Text = ex.Message
End Try
End Sub
In the e.File.FullName i can found the file's name with its path, so when i launch it as process it should open the Excel's file.
So this code works on local, but when i upload it on a web server it not works. It say "An error occurred in sending the command to the application".
I've created a .txt file to test if my application can access to the folder an i take this the "Access is denied" error.
It is strange because if i open the same Excel's file using a ASPxSpreadSheet Control of DevExpress, the file is opened.
Any solutions?
Your web service can't just open an executable on the client in normal circumstances. There's a few exceptions:
Your web server has admin privileges on the client. This typically only happens in a company LAN scenario
Your web service is the same machine as the client.
You have some sort of software running on the client that can launch the program as necessary. This requires technology outside of the web HTML/CSS/JS sandbox of the browser.
You were operating under #2. But as soon as you switch to remote clients that isn't going to work. You can't use System.Diagnostics.Process to start applications on a remote client. And you can't directly access files on the remote clients machines. Your VB.NET code is running on the server, not on the client. Only your HTML/CSS/JS runs on the client, and that's in the limited sandbox of the browser.
The general pattern to accomplish what you want is just offer a file for the user to download by writing the file to an HTTP response. The user can then open the file and it will launch their default program for editing that filetype.
Before I start, I can tell you that this is one of the worst things that you can do - is to run Excel application on the web server.
If you need to read or save Excel file(s) use Microsoft.Ace.OleDb.xx (xx-version). It will allow you to work with Excel as if it was regular DB. Moreover, if in connection string you give file name of the file that doesn't exist, it will create it.
Remember, you're on the server. And your application runs in application pool. The application pool runs under some user account, which may not have permission to open any user interface.
I remember, we had an issue with Windows service and Excel automation. Excel needs the account, which runs it to be literally logged on into machine. In other words, you need to use the credentials of the account that runs the app pool to logon into this machine. Only then Excel automation will work.
In any case. When you do Excel automation first thing you need to do is to open Excel once to get rid of all the dialogs it displays from beginning. And until you click them off, each instance will keep on showing them even if you don't see them or instance.
And last couple words - you need to use some interop assemblies, not just process.start. It will take care of some things. But Microsoft told us - they do not support or recommend Excel automation, although, admit - it is possible. Returning to paragraph #2 - to write or read data do that, not what you do. You can do #2 in IIS process. But don't do automation in process - very bad idea.
I have a dll that opens a file for processing. It attempts to find the file with FindFile() function. I also have a service that calls the dll and here is the problem - when the path to the file is a network path, FindFile() fails to find it but only when called from the service, if I call it directly from my application it finds the file. I'm sure the FindFile() function gets the same parameters in both cases as I write a log file with it. Parameter looks like this:
"\SERVER\SERVER_USERS\USERX\TEST.TXT"
I know this is 6 months after the question, but I figured I'd answer it anyway ... Usually, it is a permissions thing. If the service does not have access to the network folder, then it won't find anything. Many services run as a local system account by default, and that account doesn't have built-in access to network files. So try making sure the service is running as an account that has access to the network folder in question.
Needed to write a server text file as the output of a business process initiated by ASP.net app.
The text file writing code is in a library file using standard stream code
All worked OK in IDE.
Publish and it falls over trying to write file. IIS is reluctant to write to the file system.
Much rummaging around and hair pulling finally led to a solution. It is not pretty and only applicable in a situation where you have control over the Webserver.
Just saw your answer.
It doesn't need to be inside your inetpub or wwwroot directory for that matter, it could be anywhere, as long as security permissions are set correctly for the user under which the application is running as.
But this is actually desired. If not just imagine the consequences of allowing write access anywhere.
Also, there's no need for the virtual directory. You could create a directory like C:\ProcessOutput, and grant permissions accordingly and it should work just fine.
Another option, would be to have a service account created, and impersonate as that user within your application only for when you need to write that output file.
Solution was:
Create a physical directory on the webserver with the physical path of:
c:\inetpub\wwwroot\mywebapp\myOutputFileDirectory
Make a virtual directory that points at the directory.
Using windows explorer give write permission to the physical directory to IIS_IUSRS.
Use a physical path of c:\inetpub\wwwroot\mywebapp\myOutputFileDirectory in your Streamwriter code
Maybe the virtual path could point to somewhere more sensible across the LAN if you get the security sorted but I am sufficiently battered to accept this small crumb with gratitude.
I am getting a strange issue where I seem to have read access, because I can
1. Get a list of files from a directory (Directory.GetFiles())
2. Load an XML document using XmlDocument instance's Load() method
But I can't use File.ReadAllText() to load a text file into memory. Gives me an System.UnauthorizedAccessException. I am not even trying to read from a network directory, just a local one. I've also used System.Security.Principal.WindowsIdentity.GetCurrent().Name to check the working user which is [CompanyDomain]/[MyUserName] and this user has full access to the directory I am using. I've also checked that the directory actually exists.
My environment
1. Windows Server 2003 Standard Edition
2. Visual Studio 2008
3. Just using the built in web server that launches every time i run the project.
Note: I couldn't find the IUSR_MACHINENAME user on this machine.
Any idea what steps I should take next?
Cheers,
James
One thing to assert:
the file that can be Xml Load()-ed is the very same file that cannot be ReadAlText()-ed ?
When things get odd like this, I found that turning auditing on, at the level of the directory or even of the file, often ends up pointing me towards a proper diagnostic and hence resolving the issue.
Also: In looking online reference for ReadAllText() I noted that (oddly, I think), this exception can be caused by:
path specified a file that is read-only.
Not sure why write access should be sought by this apparent read-only operation, but, maybe just try to make the file r/w-able.
http://msdn.microsoft.com/en-us/library/72wdk8cc%28VS.71%29.aspx
<identity impersonate="true" />