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.
Related
Our company recently joined a larger company that utilizes Bit9 for application whitelisting. Previously, we had a large amount of users using Harmon.IE to interface with our Sharepoint-based document management system. I'm trying to figure out what to allow in Bit9 to allow the document open process to work in the Harmon.IE outlook add-in.
What's happening is the user tries to open a file from the Harmon.IE pane and Bit9 blocks the auto-generated, randomly-named vbs file used to launch the file from Sharepoint. Since this file is different each time and has a different hash, we can't simply approve the vbs file.
We also can't set wscript as a trusted source as many malware sources utilize wscript. Likewise, can't really allow anything that comes out of Outlook as that would open the door for malware delivery via email.
I'm trying to find out if there's a dll that I can trust somewhere in the stack that will allow these VBS files to be trusted and allowed to run.
Add OpenFilesUsingScript key with default value "False"- harmon.ie will launch files directly without using VB script
[HKEY_CURRENT_USER\Software\Mainsoft\Prefs\OpenFilesUsingScript]
#="False"
A custom rule with an action of Execute Allow on the path of the VBS with the name wild carded as deep as possible should cover you just fine.
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.
I am using asp.net C# 4.0
I have a batch which will open a text file.
Batch File query
ECHO OFF
start D:\accounts\request\08__processing\0377e792-4ca9-4550-b78c-de2bdf26611f.txt
ASp.net Code
System.Diagnostics.Process.Start("D:\\bacthFile.bat");
when i double click on the batch file its opening the text file.But when run above code its not opening any notepad.
it is not showing any exception also.
Please Help
Thanks
This is the wrong way to read a text file from ASP.NET, you need to use System.IO and put files you need to read somewhere where ASP.NET can get at them, eg.. App_data. That said, here is how to do it the wrong way: IIS runs on an invisible virtual window--it's a service. There is a way to get some services to display the UI, I forget how. In any case, you'd have to RDP onto the server, to see such a window after starting the service and goosing it into displaying a UI (this trick might not even work for IIS).
Next, as commenters noted, on IIS, you'll have one set of credentials different from your own (depends on what version of IIS)-- in any case, it will have restricted access and be somewhat sandboxed. If you set up impersonation and windows authentication in the web.config, sometimes you can get your request to run with your credentials.
Next, if the web host runs in medium trust, you might not be able to launch arbitrary apps from the asp.net appdomain.
Finally, the only way this could ever work is if your app is always running locally with casinni (the visual studio development server)-- but in that case, you could simplify things a lot by using a console app instead of asp.net unless you really need the HTML templating, say for output.
I have an ASP.Net application deployed on the server. I want to know whether it will be able to access my local system exe files on button click.
I read a lot of articles regarding this on the Internet. Some are saying it is not possible for the ASP.Net application to access local programs. While some were suggesting that it depends on Permissions, identities and other things .
I tried a similar thing on my local machine but even after giving access permission to Local System, Network Service for the file and even changing the Application Pool identity to local system, i was not able to accomplish the same...
So i just want to confirm whether this thing is possible or not...
Here is the code i am trying to execute
Dim pstartinfo As New ProcessStartInfo()
Dim p As New Process()
pstartinfo.WorkingDirectory = "D:\VS2010Projects\SignatureCaptureWindows\bin\Debug"
pstartinfo.FileName = "SignatureCaptureWindows.exe"
pstartinfo.CreateNoWindow = False
p = Process.Start(pstartinfo)
p.WaitForExit()
If (Not p.ExitCode.Equals(0)) Then
Response.Write("Image Successfully saved in Database with ID = " + p.ExitCode.ToString())
DisplaySavedImage(p.ExitCode)
Else
End If
On running on locahost, it works fine.. When i deploy it on my Local IIS, it doesn't open the exe
It is possible and requires that the application pool user has permissions to the location of the executable and permissions to execute it.
You can use the Process class to execute pretty much anything (even with different user credentials if needed).
Don't forget that trying to run an application with a UI will not generally work well, as the application pool does not run in an interactive environment (so, it can't open windows and click buttons).
You should limit yourself to executables that are not interactive, as the web server will not be able to interact with windows and such.
In your specific scenario, where you need the user to enter their signature and it gets saved - you need them to upload the signature (I am assuming an image file exists already), or create such an image on the client side (say with canvas and JavaScript). You could then upload the image and save it.
I use the following code snippet to open a local docx file and it runs fine when I press Ctrl+F5 in Visual Studio. I just click the button and the Word2007 on my machine is opened and the docx is displayed there. But after I publish the application to the production server, it didn't work. After I click the same button, nothing happened. Could someone tell me why?
What I want is to open a local stored docx in client side's Word 2007 from asp.net application. I don't want to use office COM object.
My code:
ProcessStartInfo psi = new ProcessStartInfo(#"winword.exe",#"/test.docx");
Process.Start(psi);
Many thanks.
Your code is attempting to open Word on the server and not on the client. The only reason it works in development is the the client and server are on the same machine.
You cannot open Word on the client due to browser security restrictions. However if you provide a link to the file, the user will be able to download and open the file if they have Word installed.
If you want to open a local stored document, on the client's machine, you should create a link to the document (using the path on the client's harddisk). The browser will ask the user for permission to open it, but this should work.
The reason your code worked, was because the server and the client are the same machine when debugging. The development server even runs using your profile.
In production the server can be on the other side of the world. The C# code you show in your snippet is executed on the server.
Check if the file exists in the same location.
ProcessStartInfo psi = new ProcessStartInfo()
is working on server and it is trying to pick the file from server location and it can never run client side file.
The only thing you can do is let them download the file. If they don't have office, or don't have the right compatability pack, they won't be able to open it.