0

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

NayeemKhan
  • 1,210
  • 7
  • 19
  • 38
  • 1
    Is `soffice.exe` available on the server? Is it in the `PATH` environment variable for the web service account? More to the point, what exactly are you trying to accomplish here? What benefit is there in opening an application on the _server_ console for a web application, where users aren't on that server console? – David May 18 '11 at 17:09
  • Dear david ans1. soffice.exe is available on server. ans2.web services are not in picture at all. ans3. my project have a no. of .odt files (say resumes of candidates). Resource Mgr wants to view all these profiles. The profiles are saved in a particular folder. I have listed all the resume names (file name) in a listbox with single selection mode. below that i have a button called view. On click of the button i have the complete path of the file to open it in soffice application. This is working as per my requirement in my local machine but not in iis. – NayeemKhan May 18 '11 at 17:24

1 Answers1

5

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.

Community
  • 1
  • 1
David
  • 208,112
  • 36
  • 198
  • 279
  • Very clear and concise answer that gets to the heart of this matter, being that the goal is wrong. – Chris Marisic May 18 '11 at 17:46
  • Thanks david, i appreciate your answer. I think opening file at the client would be the best way. Kindly tell me what should i do to enable the user to open the file using their local machine application. Do i need to do anything extra. Why not view button giving an open with with window to the user in this case? – NayeemKhan May 18 '11 at 17:55
  • @ Dear Chris, plz don't bother about the goal, the goal is solid, clear, right and well explain. – NayeemKhan May 18 '11 at 17:59
  • @NayeemKhan: That's just it, the goal is not solid or clear. Your approach and responses so far demonstrate this. But the good news is that, if my interpretation of the business need is accurate, this isn't going to be complicated. To answer your question, you shouldn't need to do anything special for the client machine to open the file. The client just needs the correct application installed. All the web site does is send the file with correct header information, the browser and local application take care of the rest. – David May 18 '11 at 18:03
  • @NayeemKhan: Keep in mind, however, that the file being opened on the client is *not* the same copy that's on the server. It's a local copy on the client. This means that any *changes* made to the file won't be reflected on the server. The user would have to re-upload it. To overcome this, you'd need some kind of online document editing system. Things like Google Docs (for online editing) or MS SharePoint (for client-side editing which saves to the server) address this pretty well. Any custom solution approaching Google Docs functionality would be... difficult. – David May 18 '11 at 18:05
  • @ david : thank a bunch again. Will do the same. Now may i know where u found that my goal is not clear? I have very clearly said that i want to open a file( this is my goal). Now may be the approach is wrong.(wrong in the sense, was trying to acquire serverr application to open) now, Nobody in this world is born knowing everything. Mistake in achieving a goal cant be said that as goal is not clear. – NayeemKhan May 18 '11 at 18:11
  • @NayeemKhan: Don't take it personally. Just understand that there are a number of transitions between what the business wants, how it's communicated to the developer (you), how you've communicated it to us, how we've communicated responses, etc. For example, my point about how the files aren't inline-editable from a shared server sense. That's a gray area in the requirements. Also, from our perspective, the requirement of "opening a file on the server" as opposed to "opening a file from the server" (with regards to the original approach) is confusing for new people (us, rather than you). – David May 18 '11 at 18:25
  • 1
    @Nayeem: I had the same reaction as David did. My reason is that this is an area frequently misunderstood by people new to web development. As soon as you said you wanted to launch a program for the manager to view, I knew what the problem was. – John Saunders May 18 '11 at 18:56