open a file before uploading through file uploader in asp.net - c#

I want to upload an exe to web server from client system through file up-loader and want to run/open that exe before uploading .how can i run/open that exe before uploading it.

Short answer: No way!
If you really want to execute it client side, the user has to do it manually, JavaScript and jQuery are not going to execute an application locally.
if you want to execute it on the server side, you should first upload it to the server.
why are you trying to do this? can you explain a bit your use case?

If you're trying to execute on the server then you'll have to upload it first. Plain and simple.

You cannot make the web client open a file or even access the files because of browser security restrictions. All you can do is access the immediate file name (e.g., file.ext) and file content once the user browses, manually selects the file, and the form submits.
The reason for this restriction is that, if a website could execute files, any site could very easily install malware on a person's machine.
On the other hand, to execute the EXE on the server, it must first be uploaded.

Related

How to get the local desktop path of the users file when the application is hosted from server?

I am trying to run a macro-file that will be present in users desktop via my .net website, hence I would like to know how I can get the path of that macro file in my code and open it.
I am currently using following described code to get the path, and I think that this must be trying to take the path from server computer but I would like to get this from users computer, this particular macro file will open internet explorer and navigate to certain website and download a report to local computer hence I would like this to be run from users side.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Is it possible to get the path automatically or should i get that from user.
please provide suggestion.
You are hosting a website, which is using a web server like IIS and the user access the site using a browser like edge, chrome, now the file is in user desktop, so the main question remains,
Does the browser process have the access to the file system of the user
Mostly no, especially not via the call Environment.GetFolderPath(Environment.SpecialFolder.Desktop);, this will be good for running it on hosted sever, where w3p.exe process is accessing the file system with required permissions
For the end user desktop
You need to provide the file dialog box, let user select the file / directory and need to plan to serialize the file to the sever (upload) for doing any processing. You can binary serialize the file using a provider like protobuf, msgpack to achieve the necessary functionality
Code you have provided, is good for for the process where you have direct control, like Console, WPF, which runs on the system under certain permission and thus access the file system for processing

Set *.exe file properties after upload to server

I'm trying to find a way to write "meta" information to EXE files that are uploaded to my IIS/ASP.NET web service. Here's a little bit of background:
I need to write one arbitary string into the properties
It'll be URL that I write as "metadata", if that matters
Example: https://example.com/someFolder/someOtherFolder
The files are mainly installers originally created by InnoSetup
The web server is running IIS 7.5 with ASP.NET on top of Server 2008 R2 (Standard)
Why am I trying to write this information?
Ultimately the EXEs are made available to users for download. When the application runs, it needs to know the web URL in order to execute properly. Currently we have a plain text box where the user can input the URL, but that has proven to be error prone (despite prompting/error checking/...)
Why can't I just write the metadata in the EXE when it's created?
I could do that, but the EXE could be uploaded to a variety of different servers, each with their own unique URL "metadata". I'm trying to avoid creating a separate build script for each server.
Why not just create a *.zip file with the *.exe and an extra piece of metadata?
I suppose I could do that too -- but then the user would have to actually unzip the download so that the real installer could read the metadata. I had something similar to this before and most people never unzipped the full download and that posed its own problems.
So is this even possible? I guess as a last resort I could use the uploaded EXE to create a new EXE, but I'm trying to avoid doing that (gets into problems with signed EXEs, etc.)

How to save .pdf file from server to client side?

I need some suggestion about how to save .pdf file from server to client side. I'm using C# console application to generate pdf file and save in server local c and I manage to do it by using .ExportToDisk(ExportFormatType.PortableDocFormat, report). Now I need to save the file to client side rather than save in server local c because my user aren't allowed to access the server. Appreciate if someone can help me about this. Thanks
Your best option would be to export to a UNC path which the users can access. Don't forget your console application will have to run as a user with write access to the UNC path.

how to make a process run on iis?

Dear all, i have following code to open a file on click of a button
System.Diagnostics.Process.Start("soffice.exe",filepath);
soffice.exe is to open .odt files & filepath is containing the complete path of the file which i want to open.
This is working perfectly when i m executing the code on my local system, but as i m hosting it on the iis server (5.1), its not taking any action (event not throwing any error too). My filepath is accessing a folder in my project, not outside. Kindly suggest the possible reasons and solutions
In response to your comment above...
First of all, by "web service account" I don't mean web services. I mean the service account on the web server under which the web application runs. This could perhaps be the account of the user logged in to the website, or the default IIS account, etc. The best way to address this would be to fully qualify the path to soffice.exe when calling it, that way you don't have to worry about the PATH environment variable. (Additionally, you don't have to worry as much about another application being run maliciously or by accident and doing something unexpected with unknown permissions.)
Second, there seems to be a critical design flaw in your approach. Even if you do manage to get the application to launch on the server, it's going to launch on the server. Is the resource manager sitting at the actual web server? If not, then opening the file in the application on the server will do him no good whatsoever. If he is sitting at the server, then he's the only person who can use this.
You don't want to open the file on the server. You want to deliver the file to the client. Then if the user (the resource manager in your example) can open the file in soffice.exe on his local machine. If his environment is set up correctly, it should open automatically. (Though the browser will also give him the option to save the file locally and then open it.) Simply linking to the file should suffice. Is there any particular reason why it wouldn't?
If you need to use a form post rather than simply a link in order to deliver the file, you can still stream the file from your server-side code. Here's a previous question discussing how to do that. Basically the process involves clearing the output buffer, setting the headers (content length, content type, suggested file name, etc.), streaming the bytes, and flushing/closing the output buffer.

sync database to uploaded file using Windows Service or website code

I have a website that occasionally needs to have a handful of the tables in its database updated. The updates come from another system that exports to comma delimited text files. I can then either FTP the text files to the web server, send them in through an admin upload page, or manually log in to Remote Desktop to download the text files. I have all my C# code written to parse the files, check the database contents, and decide what to do.
Should I code the sync logic to be part of a file upload page, protected in the admin section of the site or should I create a Windows Service that constantly looks for files to process in a particular directory that I can drop files in through FTP?
I have used Windows Services in the past and they have worked great, but if I ever have to make a change to the code it can take longer than it would if I just had to modify an ASPX.
Are their security benefits one way or another?
Performance benefits?
ASPX page wins the "ease of maintenance" category.
I would create a Windows Service to watch a secure folder and use a directory watcher to look for new files. Since the files are coming from another system, it is asynchronous in nature, and it is much more performant to have a Windows Service running separately to watch for updates as they happen. It can also parse the files and update the database for you.
Depending on who maintains the remote system, the easiest way is to grant permission to the service to access the files on a secure, shared folder. Then you won't need to do anything manually.

Categories

Resources