0

I want that the user open an explorer on his computer not on the server.

I am using :

System.Diagnostics.Process.Start("explorer.exe", folderLocation);

folderLocation is on the same server like \serverIP\folder.

Into iis Express with local configuration it's working , but it does not work on my iss in production. There are no error, just return Null. I have checked some previous stackoverflow who advice to check this : On service IIS Admin Service : Check "Allow service to interact with desktop".

1

But it doesn't work

Do you have any advice to me ? Thank you.

Cleptus
  • 3,446
  • 4
  • 28
  • 34
  • 4
    That's running explorer *on the server*. Which almost always doesn't have any users logged in. I often see this in the context that the developer expects it to launch on the same machine as the *browser* but that's not the case. For VERY GOOD reasons, arbitrary websites aren't allowed to launch arbitrary programs on the user's machine. It "works" in your testing when the "server" and client machines are the same machine and IIS Express isn't running as a service. – Damien_The_Unbeliever Jul 18 '22 at 08:26
  • 2
    What are you actually trying to do? I am pretty confident in saying "opening an Explorer Window on the server" is not it. Do you happen to want the user to choose a local file from their machine? – Fildor Jul 18 '22 at 08:35
  • I want that the user open an explorer on his computer not on the server. – Ludovic MOISSON Jul 18 '22 at 09:09
  • 2
    "_I want that the user open an explorer on his computer not on the server_" Then you should not change server settings, but use a user control that allows browsing directories. Since you mention IIS, is it a website? – Cleptus Jul 18 '22 at 09:13
  • @Cleptus yes i am on MVC app , and i want to open an explorer. So i see Process.Start do the job. But only on my iis express on local test. – Ludovic MOISSON Jul 18 '22 at 11:22
  • Getting null is normal behavior, specifically for explorer.exe. It indicates that Explorer was already running so could be used to create a window to display *folderLocation*. The behavior of a singleton process, the advantage for Explorer is that you can know it happened from the null return value. – Hans Passant Jul 18 '22 at 11:41
  • ok thank you for your answer, but actually i search to open a folder by a clic from a mvc website. I think process.Start it's the best choice ( maybe not i don(t know if there are another solution ) . In my local environment i have tested some Process.Start("explorer.exe",folderLocation) it's all working but when i push the solution it didn't work. So i supposed it' s on IIS configuration. – Ludovic MOISSON Jul 18 '22 at 12:40
  • @LudovicMOISSON check this [related answer](https://stackoverflow.com/questions/30567296/how-can-i-use-openfiledialog-in-c-sharp-mvc) – Cleptus Jul 18 '22 at 13:42
  • thank you for your answer , but i don't need to use an input. Maybe i need to create an other topic, because i think i don't use the right thing. I need to replace this code ` ` because it doesn't work on chromium explorer. I have found `Process.start("explorer.exe", .... ) ` but i don't know if it's the best choice – Ludovic MOISSON Jul 18 '22 at 13:54
  • 1
    Be careful of what you wished for. A web app that can open Windows Explorer on an end user's machine has the potential to execute other operations that can harm that end user in many ways. That's why browser vendors put web apps in sandboxes and prevent such from happening in the first place. – Lex Li Jul 18 '22 at 14:21
  • 1
    Besides, "In my local environment ... it's working" is the illusion for every new developers, but the reality is cruel, https://halfblood.pro/web-application-differences-in-visual-studio-and-iis-60fec7e311b3 – Lex Li Jul 18 '22 at 14:23
  • The desktop you are allowing IIS to interact with, is the server's, not the client's. And nobody looks at the server one – Hans Kesting Jul 18 '22 at 20:40
  • To me this question is a big X-Y problem. You need the user to access files from a network share, you found it it is not allowed (it is a security risk) and then you ask on how to start a process in the server (which in this scenario would solve nothing). – Cleptus Jul 19 '22 at 10:18
  • Does this answer your question? [Can Google Chrome open local links?](https://stackoverflow.com/questions/2087894/can-google-chrome-open-local-links) – Cleptus Jul 19 '22 at 10:18

1 Answers1

1

For the user to open a file picker, on your website in your HTML code you can include the following:

<label for="file">Select a file:</label>
<input type="file" id="file" name="file">

You can find more information here, including how to read the content of the picked file using javascript: https://www.w3schools.com/tags/att_input_type_file.asp

Geoffrey McGrath
  • 1,663
  • 1
  • 14
  • 35