1

I found out that calling OpenFileDialog from an application running as administrator will make the dialog unable to detect network shared folders.

Here's my app.manifest file, the purpose is to force the application to always run as administrator.

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

Here's the XAML code:

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="built-in" Margin="0,0,308,152" Click="Button_Click"></Button>
    </Grid>
</Window>

Here's the CS code:

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog();
            openFileDialog.Filter = "txt (*.txt)|*.txt|All files (*.*)|*.*";
            openFileDialog.ShowDialog();
        }

    }
}

Now if there are a few other machines sharing the folders with the machine where this code is run, then the OpenFileDialog is unable to detect the share folders.

  1. If I don't force the application to run as administrator, then the OpenFileDialog can see those shared folders
  2. I can see the shared folders in file explorer.

Why is this so? Is it possible to be fixed?

Graviton
  • 81,782
  • 146
  • 424
  • 602
  • 1
    What do you mean? Network shares don't just appear in `OpenFileDialog` either - otherwise you'd see all shared folders from all computers on your domain. You'd have to navigate to a server, eg from the Network node, to see the shared folders it publishes. – Panagiotis Kanavos Feb 27 '19 at 08:33
  • Your admin account must have access to these shares and be logged on it – Pavel Anikhouski Feb 27 '19 at 08:36
  • @PanagiotisKanavos,in this case, the network share folders have the explicit permission to appear at other connected machines, and one can know the share folders by looking at the file explorer – Graviton Feb 27 '19 at 08:39
  • @PavelAnikhouski,the admin account does have accessed to the share folders-- as looking at the file explorer can confirm – Graviton Feb 27 '19 at 08:39
  • Maybe this helps: https://social.msdn.microsoft.com/Forums/windows/en-US/f0073f80-cedb-4b7a-96b9-20e4b22c2424/folderbrowserdialog-does-not-show-network-drives-on-windows-8?forum=windowscompatibility – Denis Schaf Feb 27 '19 at 08:39
  • @Graviton there's no such *permission*. For those shares to appear in file explorer they were added through a group policy or another mechanism. How were they added? – Panagiotis Kanavos Feb 27 '19 at 08:40
  • @DenisSchaf this is a question about shares, not network drives and the FileOpen dialog, not Folder Browse – Panagiotis Kanavos Feb 27 '19 at 08:42
  • @PanagiotisKanavos, is it really relevant? Because if I run the application as normal ( not as administrator) , then I can see the shared folders – Graviton Feb 27 '19 at 08:42
  • In case of mapped drives, those mappings are only for the local user. – Nawed Nabi Zada Feb 27 '19 at 08:43
  • @Graviton obviously. Because that mechanism doesn't seem to work in the elevated profile. Perhaps because it *hadn't* affected that profile. Or because it's a shell extension that doesn't work there? It's not something that can be "fixed" by code. – Panagiotis Kanavos Feb 27 '19 at 08:43
  • 2
    @Graviton what happens when you use any other application, eg Word? Can you see those file shares then? What happens if you start *Word* as an administrator? Those dialog boxes are provided by the OS, not .NET. If the same behaviour appears in other applications, there's not much you can do – Panagiotis Kanavos Feb 27 '19 at 08:44
  • 1
    @Graviton *on the other hand* you can modify the default flags used when the Open/Save file dialog appears and control what's shown. That's why it's important to know *how* those shares were published to all users. Maybe it's an item class that can be enabled – Panagiotis Kanavos Feb 27 '19 at 08:46

0 Answers0