1

I'm working on a Blazor Server Side application which is used ONLY inside our network. The application handles Building Permits. So far so good.

Historically, the permits were done manually and all related files (blueprints, letters etc) where saved on our fileserver and accessed through Windows Explorer.

To be able to keep the same workflow for file handling, I am tasked to open windows explorer from the Blazor app.

I'm quite aware that this is far from recommended and I tried talking people out of it, but to no avail.

So: is there a way to open a specific location in Windows Explorer directly. I know that you can link to a HREF="file:\my-server\path\to\share", but that only shows the directory listing. There is no way to add files, copy, paste, rename, whatever...

UPDATE (2021-07-08): This is in a controlled environment. The application is NOT public. I would never ever do such a thing for a public application. The people who use the application are pretty limited and will know about the functionality.

Gilles Radrizzi
  • 999
  • 3
  • 10
  • 20
  • Process.Start? The old fashioned way, for an old fashioned workflow? [thread](https://stackoverflow.com/questions/1132422/open-a-folder-using-process-start) I'm not sure if that would work but you can give it a shot... – Nikki9696 Jul 06 '21 at 14:16
  • Actually, it probably won't. Here's a thread about using a custom file handler protocol, maybe it's a way? [link](https://answers.microsoft.com/en-us/microsoftedge/forum/all/launch-a-desktop-exe-application-from-aspnet/2e78ee37-5e52-4c79-80b3-b6a640fab527) – Nikki9696 Jul 06 '21 at 14:19
  • That only works on the development machine as Process.Start starts the process on the server. In DEV that opens Windows Epxlorer as server and client are the same. However, it won't work in production. The server can't start a process client-side – Gilles Radrizzi Jul 06 '21 at 14:23
  • What you are asking for is not specific to Blazor. Rather, you should ask yourself whether you as a user of a web browser have ever seen this functionality anywhere. It might be possible with obsolete versions of Internet Explorer, but not with any modern browser. – Kirk Woll Jul 06 '21 at 14:58
  • 1
    @Nikki9696 pointed me in the right direction. Using a custom URI handler seems to work. A first simplified test is kind of promising. – Gilles Radrizzi Jul 06 '21 at 19:59

4 Answers4

1

You can't open explorer from the browser on the client unless you make a plugin for the browser (or your own browser).

Even if you could open Explorer from Blazor Server, it'd open on the server, not on the client.

That said, making your own browser (which supports that), is not a necessarily complicated task these days (look at CefSharp, WebView2 or similar), if that's a possibility, but that's WAY WAY outside what can or should be explained in this question.

Or you can make your own filebrowser on the web (using Blazor components).

But definitely not open explorer from a browser... and if you find a way on a standard browser, please report it because that's a HUGE security flaw.

Jcl
  • 27,696
  • 5
  • 61
  • 92
  • I'm currently trying with adding my own custom URI Scheme handler which seems to work. Given that I'm in a controlled environnement, this should work fine. I would just need to add the necessary Registry entries on the clients – Gilles Radrizzi Jul 06 '21 at 20:00
1

For those who need to do the same thing, I figured out how to do it. Nikki9696 pointed me in the right direction in his comments.

The browser will not open Windows Explorer on the client directly (which is a very good thing as pointed out in other answers). But I implemented a custom URI Scheme

Here is a simplified version of the code:

class Program
{
    [STAThread]
    static void Main(string[] args)
    {
        if (args.Length > 0)
        {
            string path = string.Empty;
            path = args[0].Replace("my-app:", string.Empty);
            path = System.Web.HttpUtility.UrlDecode(path);
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);
            }
            System.Diagnostics.Process.Start("explorer.exe", path);
        }
        else
            Console.WriteLine("No Argument specified");
    }
}

This works. I just need to add the Custom URI Scheme in the clients registry.

Gilles Radrizzi
  • 999
  • 3
  • 10
  • 20
1

The only way to get this done within blazor is by using a custom protocoll.

Create a simple C# console app and bind the compiled exe to your protocoll. The protocoll needs to installed on all client PCs (you can do this via group policies).

Within your blazor app you'll link to you custom protocoll with any parameters.

Keep in mind that you'll need to open a new tab every time because of https://github.com/dotnet/aspnetcore/issues/29259

Marvin Klein
  • 1,436
  • 10
  • 33
0

If you COULD do that, it would be a bug in Blazor, and Microsoft would have to patch it immediately. It's a horrible, horrible idea. Like-- epically terrible.

If people will be accessing files on the individual machines, then you'll need to write apps for those machines, not a web app. Maybe they can upload files to the server.

If you can host all the files on your IIS server (I'm assuming), then you have to configure folders, links, virtual directories etc. etc.

Bennyboy1973
  • 3,413
  • 2
  • 11
  • 16