Search code examples
c#azure-blob-storage

How do I open Azure Storage Explorer at a particular subfolder programatically?


I can give my user a good experience opening Windows File Explorer with the following code.

var psi = new System.Diagnostics.ProcessStartInfo()
        {
            FileName = startPath,
            UseShellExecute = true
        };
System.Diagnostics.Process.Start(psi);

I want to do something similar for Storage Explorer.

I have tried the following

var arguments = $"--account-name mystorage --container images --path mysubfolder";

var userDirectory = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

// get the path to the Azure Storage Explorer executable
var workingDirectory = userDirectory+"\\Programs\\Microsoft Azure Storage Explorer";
var fullExeFileName = workingDirectory+"\\StorageExplorer.exe";

if (!Directory.Exists(workingDirectory)) 
{
    throw new DirectoryNotFoundException(workingDirectory); 
}

if (!File.Exists(fullExeFileName)) 
{
    throw new FileNotFoundException(fullExeFileName); 
}
       
var processStartInfo = new ProcessStartInfo
        {
            FileName = fullExeFileName,
            Arguments = arguements,
            UseShellExecute = true,
            WorkingDirectory = workingDirectory
        };

Process.Start(processStartInfo);

Which opens StorageExplorer but not at the relevant subfolder.

I have opening a directlink in the browser but this presents the user with a dialog box which is not what I want.

I have tried the visual studio command prompt but cant get the arguments working.

With command:

storageexplorer "--account-name mystorage"

the following log file gets generated:

[2025-01-26T22:15:40.815Z] (main:17928) <NONE> Log level: info
[2025-01-26T22:15:40.815Z] (main:17928) <INFO> Startup app state:  {
    lastWindowState: {
      rect: { x: 900, y: 652, width: 1760, height: 902 },
      maximized: false
    }
  }
[2025-01-26T22:15:40.907Z] (main:17928) <INFO> Calling handleQuitOrRelaunch from quit
[2025-01-26T22:15:40.907Z] (main:17928) <INFO> Quitting, sessionEnded: false, force: true, quitOrRelaunch: quit
[2025-01-26T22:15:40.907Z] (main:17928) <ERRO> Error occurred while trying to actually quit: {}
[2025-01-26T22:15:40.908Z] (main:17928) <INFO> Calling quit, bye!

Solution

  • How do I open Azure Storage Explorer at a particular subfolder programatically?

    I agree with stuartd's comment, Azure Storage Explorer does not support direct navigation to a specific container or subfolder via command-line arguments.

    As of now, you need use direct link to access the Azure Storage Explorer at a particular subfolder .

    Code:

    using System;
    using System.Diagnostics;
    
    class Program
    {
        static void Main()
        {
            string storageExplorerUri = "storageexplorer://?v=2&tenantId=(tenant-id)"
                + "&type=blobPath&path=<path name>%2F&container=(container name)"
                + "&serviceEndpoint=https%3A%2F%2F(account name).blob.core.windows.net%2F"
                + "&storageAccountId=%2Fsubscriptions%2Fxxxx%2FresourceGroups%2Fxxx%2Fproviders%2FMicrosoft.Storage%2FstorageAccounts%2Fxxx"
                + "&subscriptionId=xxxx";
    
            Process.Start(new ProcessStartInfo
            {
                FileName = storageExplorerUri,
                UseShellExecute = true
            });
    
            Console.WriteLine("Opening Storage Explorer...");
        }
    }
    

    The above code will open Azure Storage explorer and navigate to dialog box like below:

    Explorer:

    enter image description here

    Authenticate with user:

    enter image description here

    Now it will navigate to particular directory in Azure storage explorer.

    Portal:

    enter image description here

    Reference: Azure Storage Explorer direct link | Microsoft Learn