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.
- If I don't force the application to run as administrator, then the
OpenFileDialog
can see those shared folders - I can see the shared folders in file explorer.
Why is this so? Is it possible to be fixed?