Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access single file or folder from IStorageFolder by name #17771

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nickodei
Copy link
Contributor

@nickodei nickodei commented Dec 14, 2024

What does the pull request do?

This PR addresses #17276. It allows to access a single file or folder by name given you have already a folder (IStorageFolder).

What is the current behavior?

You can currently archive this by iteration over the whole folder with GetItemsAsync() and pick the file with the given name. This has performance considerations and therefore, when applicable, the implementations tries to access the file directly.

What is the updated/expected behavior with this PR?

When you get a folder (IStorageFolder) e.g through a file-picker, you can access the child file/folder by name directly, returning IStorageFile or IStorageFolder depending on the called method.

How was the solution implemented (if it's not obvious)?

The interface IStorageFolder was extended as follows:

interface IStorageFolder
{
     Task<IStorageFolder> GetFolderAsync(string name);
     Task<IStorageFile> GetFileAsync(string name);
}

Therefore, an implementation for the following platforms was provided:

  • Android (DocumentsContract and the query method)
  • Browser (FileSystemDirectoryHandle)
  • Desktop (.NET Path.Combine)
  • IOS (.NET Path.Combine => NSUrl)

Testing

Tested it on following platforms:

  • Desktop
  • Android
  • Browser
  • IOS (dont have an IOS device)

Extended the ControlCatalog for testing:

image

Checklist

Breaking changes

No breaking changes, this only extends the public interface

Fixed issues

Fixes #17276

@nickodei nickodei marked this pull request as draft December 14, 2024 15:47
@nickodei
Copy link
Contributor Author

I was not able to have an Android-Implementation that does not iterate trough the whole folder to find the first Item with the given name. The other thing is, that I don't have an IOS device to test the IOS-implementation.

@nickodei
Copy link
Contributor Author

nickodei commented Dec 18, 2024

Questions:

  • Should I return IStorageFolder or IStorageFolder? ? => When nullable, which Excetions should be catched and which should be thrown (e.g getDirectoryHandle throws 4 different Exceptions. Should I catch all of them and return null?)
  • Can I write tests for it or is it enough that I manually tested it?
  • How to I resolve the build error?

@nickodei nickodei marked this pull request as ready for review December 18, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access single file using BclStorageFolder
2 participants