Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All, I am using bellow code to simply open a file from a deployed (IIS 7) version but it seems it doesn't work. I am writting the code in bellow
C#
try
{
   string path = "C:\\abc\\CSharpNet.pdf";
   Process p = new Process();
   Response.Write(path);
   Process.Start(path);
}
catch (Exception ex)
{
  Response.Write(ex.Message);
}


for this i have tried followings as well in (Web.config)
<identity impersonate="true" userName="PC\username" password="pass"/>


IIS Admin Services in services (Allow services to interact with desktop)
I have also tried to add full control permission for (IIS_USER, NETWORK SERVICES, LOCAL SERVICES) users to the "C:\abc" folder

I have also changed the Pool to run under Local Services

all above didn't help. It only runs perfect from development machine, but once its deployed its not running..

So how can I use Process.Start(filePath) to open/run some batch files?

Thanks,
Posted

Yes, it works fine.
It also annoys the heck out of your web server administrator.

The code runs on the server. Not the client.

So when you run a process, it runs on the server. Not the client. Where you can't see it. But the web server admin can.

When you ran it for development, the server and the client were the same machine, so it looked like it worked fine. When you deployed it and the server is a different physical PC, it looks like it doesn't.

That approach will not work. If you want to open a PDF on the user PC, then send it to them.

[edit]Typos - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 23-Jun-12 14:19pm    
No, it does not run on client. But it runs. On server. It works fine. Not on client. How much do I need to repeat that to make it clear? :-) My 5.
--SA
Like OriginalGriff said, you can NOT use Process.Start in a web application unless you really do want to run something on the web server.

You have no way at all of remotely starting a process on a browser from the server.

If you want to open a PDF file on the client, you send the client the PDF file and it's up to the client how to handle the document, not your server code.

If the user doesn't have a PDF viewer installed, they'll get the option to save the file.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 23-Jun-12 14:20pm    
Right, a 5.
--SA
Abdul Rahman Hamidy 23-Jun-12 23:57pm    
Thanks for the reply, the situation is that i would like to open PDF, world and excel files, I have gridView with a link button that should open the desired file from a shared folder in the server, therefore i am using Process.Start to open the desired file. as i mentioned the privileges are assigned but still unlucky to do the job.
Dave Kreskowiak 24-Jun-12 1:02am    
We've already told you that's not going to do what you want. Using Process.Start will ONLY start those apps ON THE WEB SERVER. It will NOT start anything on the client. ASP.NET code executes on the SERVER SIDE only!

It's impossible to start a process/application on the client from the web server.

The only thing you can do is send the document file, be it a .PDF, Excel or Word document, or whatever doc type, to the client and the client will give the user the option to open it, if there is a viewer installed for it, or save the file to disk to view later.
Abdul Rahman Hamidy 24-Jun-12 2:02am    
I exactly don't understand, but there might be a lot of files (>1000), do i need upload all of them in server so that the user could be able to view it? do you think it would be a good idea?
Dave Kreskowiak 24-Jun-12 10:28am    
Yes, you have to put those files on the server if the user is going to be able to view them in their browser. If the server can't get at them, how is it going to send them to the user??

If you don't know how to send a file back to the user, you seriously need to pick up a beginners book on ASP.NET and work through it. This is a very basic skill in these kinds of apps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900