Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ See [this](./install-old.md)

## API

#### [Android only] `DocumentPicker.pickDirectory()`
#### [Android and Windows only] `DocumentPicker.pickDirectory()`

Open a system directory picker. Returns a promise that resolves to (`{ uri: string }`) of the directory selected by user.

Expand Down Expand Up @@ -66,7 +66,7 @@ If specified, the picked file is copied to `NSCachesDirectory` / `NSDocumentDire

This should help if you need to work with the file(s) later on, because by default, [the picked documents are temporary files. They remain available only until your application terminates](https://developer.apple.com/documentation/uikit/uidocumentpickerdelegate/2902364-documentpicker). This may impact performance for large files, so keep this in mind if you expect users to pick particularly large files and your app does not need immediate read access.

##### [UWP only] `readContent`:`boolean`
##### [Windows only] `readContent`:`boolean`

Defaults to `false`. If `readContent` is set to true the content of the picked file/files will be read and supplied in the result object.

Expand Down Expand Up @@ -107,7 +107,7 @@ The display name of the file. _This is normally the filename of the file, but An

The file size of the document. _On Android some DocumentProviders may not provide this information for a document._

##### [UWP only] `content`:
##### [Windows only] `content`:

The base64 encoded content of the picked file if the option `readContent` was set to `true`.

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default class DocumentPicker {
}

static pickDirectory() {
if (Platform.OS === 'android') {
if (Platform.OS === 'android' || Platform.OS === 'windows') {
return RNDocumentPicker.pickDirectory();
} else {
return Promise.resolve(null);
Expand Down
26 changes: 26 additions & 0 deletions windows/ReactNativeDocumentPicker/RCTDocumentPickerModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,32 @@ public async Task<List<JSValueObject>> Pick(JSValue options)
return result;
}

[ReactMethod("pickDirectory")]
public async Task<JSValueObject> PickDirectory()
{
TaskCompletionSource<JSValueObject> tcs = new TaskCompletionSource<JSValueObject>();

await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
var openFolderPicker = new FolderPicker();

openFolderPicker.ViewMode = PickerViewMode.List;
openFolderPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openFolderPicker.FileTypeFilter.Add("*");

var folder = await openFolderPicker.PickSingleFolderAsync();
JSValueObject obj = new JSValueObject
{
{ "uri", folder.Path }
};

tcs.SetResult(obj);
});

var result = await tcs.Task;
return result;
}

private async Task<JSValueObject> PrepareFile(StorageFile file, bool cache, bool readContent)
{
string base64Content = null;
Expand Down