Hi @Peter Bons ,
Update: Upgrading the system from 10.0.22000.0 to 10.0.22621.0 fixed the issue.
The error you said did not appear. But after I added the microsoft.windows.sdk.net.ref in your file, I can use StorageFile. If you want to use a similar approach in winform .net 6.0 to the project you have already created. You can take a look at my code below: I start it with a button and type the output into a richtextbox.
private async void button1_Click(object sender, EventArgs e)
{
var path = @"C:\Users\Administrator\OneDrive\OneDrive.pdf";
if (string.IsNullOrWhiteSpace(path) || !File.Exists(path))
{
richTextBox1.AppendText("Provide a valid path pointing to a file on OneDrive folder\nFor Example: C:\\Users\\pbons\\OneDrive - Brink\test.txt\n");
return;
}
var file = await StorageFile.GetFileFromPathAsync(path);
var props = await file?.Properties.RetrievePropertiesAsync(new[]
{
"System.FolderNameDisplay",
"System.StorageProviderFileRemoteUri",
"System.StorageProviderId"
});
foreach (var prop in props)
richTextBox1.AppendText($"{prop.Key}: {prop.Value}\n");
richTextBox1.AppendText($"DotNet version: {Environment.Version}\n");
richTextBox1.AppendText($"OS version: {Environment.OSVersion}\n");
}
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.