✅ Folder selector can not select folder from phone

Hi there, as the title suggests i am unable to select a folder on my phone programmatically. For some reason the OK button is also grayed out.
c#
private void BtnSelectFolder_Click(object sender, RoutedEventArgs e)
{
using (var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog())
{
folderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}

string selectedPath = folderBrowserDialog.SelectedPath;

SelectedFolder = selectedPath;
}
}
c#
private void BtnSelectFolder_Click(object sender, RoutedEventArgs e)
{
using (var folderBrowserDialog = new System.Windows.Forms.FolderBrowserDialog())
{
folderBrowserDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

if (folderBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}

string selectedPath = folderBrowserDialog.SelectedPath;

SelectedFolder = selectedPath;
}
}
No description
13 Replies
jcotton42
jcotton426d ago
Your phone is probably connected using MTP, which is not a real filesystem, but rather a protocol like FTP. I’m not sure why that dialog would show MTP devices anyways.
electronic heartbreak.
It indeed connects through MTP. Do you have some keys on which i can search or have some tips to tackle this?
jcotton42
jcotton426d ago
I’m afraid not. You’ll have to look both how to get the folder dialog to permit MTP, and also might need to add MTP support to your app in some way. Also, fwiw, this is the older folder dialog, there’s a newer one that might handle MTP better. What version of .NET are you targeting?
electronic heartbreak.
I guess youre looking for this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
I use WPF. I could choose between WPF Application and a WPF .NET Application, so i went for the second. Didnt know if that choice had much consequences.
jcotton42
jcotton426d ago
$newproject
MODiX
MODiX6d ago
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework. .NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended. https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
jcotton42
jcotton426d ago
I believe.NET 6 (7?) switched to the new dialog. Currently we’re on .NET 8.
electronic heartbreak.
i should have seen this image earlier 🤣 . I clicked on the one with NO Let me create a new project and paste the stuff over.
jcotton42
jcotton426d ago
To be honest. The Framework templates really should be hidden or at least show a warning.
electronic heartbreak.
I created a new project. I should now use OpenFolderDialog right?
jcotton42
jcotton426d ago
Dipesh Kumar
.NET Blog
WPF File Dialog Improvements in .NET 8 - .NET Blog
Announing OpenFolderDialog control and other file dialog properties in WPF in .NET 8.
electronic heartbreak.
this is better haha! I sadly cant find the MTP
No description
electronic heartbreak.
yeah im done with this stuff 🤣 spend nearly 5 hours on this while i also could copy paste stuff myself