Click here to Skip to main content
15,041,525 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Application: WindowsService1.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception.

Exception Info: System.InvalidOperationException at System.Windows.Forms.CommonDialog.ShowDialog(System.Windows.Forms.IWin32Window) at System.Windows.Forms.CommonDialog.ShowDialog() at WcfService1.Service1+<>c__DisplayClass1_0.b__0() at System.Threading.ThreadHelper.ThreadStart_Context(System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ThreadHelper.ThreadStart()

What I have tried:

I tried by setting up user as currentuser,still i cannot open filedialog
Updated 1-Jun-21 4:24am

1 solution

A Windows Service is a non-interactive process which runs in the background. There could be multiple users logged in to the computer, or there might not be any users logged in to the computer. Therefore, a service cannot show any user interface at all.

There used to be an option to allow services to interact with the desktop. However, this was a security issue, and has been disabled in all recent versions of Windows.

Your only option is to have an application running on the user's desktop which subscribes to an event on the WCF service and displays the appropriate UI:
How to: Create a Duplex Contract - WCF | Microsoft Docs[^]
Elite Labs 1-Jun-21 11:00am
Is i need to build two setups one for service and another one for ui
Richard Deeming 1-Jun-21 11:03am
Yes, you'll need two different applications.
Elite Labs 1-Jun-21 11:04am
Can u describe how to connect both setups interlinked
Richard Deeming 1-Jun-21 11:08am
The Microsoft Docs link in my answer explains how to connect the two applications using a duplex WCF contract.
Elite Labs 1-Jun-21 11:20am
okay,thank's a lot i will give a try and get u back..
Elite Labs 3-Jun-21 4:05am
I have made two wcf libraries each for client and server and installed them as windows service ,it still throws same error ,it doesn't triggers explorer
Richard Deeming 3-Jun-21 4:07am
Why have you created two WCF libraries and installed them both as services?!


Read my solution again. You need ONE WCF service running as a Windows service, and ONE desktop application running on the user's desktop which communicates with that WCF service.
Elite Labs 3-Jun-21 4:16am
i'm consuming wcf library as windows service in Angular application ,so when i click upload in angular the windows service should trigger the custom file explorer.if i use desktop application .is it possible to trigger the desktop application using windows service
Richard Deeming 3-Jun-21 4:20am

Code running in a web page CANNOT communicate with services on the client PC, and it CANNOT access the file system on the client PC.

Use an <input type="file"/> to let the user select a file to upload. That is your only option.
Elite Labs 3-Jun-21 4:23am
But on using that i cannot get full path which is required for me,i seen in some application they are getting full path how is this possible when there are security restrictions to get full path
Richard Deeming 3-Jun-21 4:28am
The full path of the file ON THE CLIENT is completely useless to your code which is running ON THE SERVER.

A file which exists on my PC at Z:\Random Stuff\Test.pdf will NOT exist on your server. Or, if it does, it won't be the same file.

The code running on your server CANNOT access the files on the user's computer, unless the user uploads the file to your server. At which point, the full path is completely irrelevant.
Elite Labs 3-Jun-21 4:32am
I'm running a thread on client machine which is running in background which accepts the filepath as input and then fetch the file from that location and send it to server in background without freezing UI.In order to perform this i need complete path of the input file.
Richard Deeming 3-Jun-21 4:34am
Not in Angular code running in a browser you're not.

Code running in a browser has no access to the client's file system, except via the file input, or the experimental FileSystem API[^].
Elite Labs 3-Jun-21 4:37am
I have been working on IBM Datacap navigator which picks up entire path of the file.It is a web application how is it possible
Richard Deeming 3-Jun-21 4:41am
No idea. Ask IBM.
Elite Labs 3-Jun-21 4:48am
For that application UI to trigger in browser we have to start windows service
Richard Deeming 3-Jun-21 5:00am
You're still not getting it.

Code running in a browser CANNOT access services running on the user's computer. It CANNOT access the file system on the user's computer, except via extremely limited APIs. And the full path of a file on the user's computer is completely meaningless to code running on the server.

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

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