Create Folder with the folder name as desired user on UWP

306 views Asked by At

How do I create a folder in the application package to the user folder name as you wish? After clicking createBtn, it will display a pop up for the user to type the folder name in accordance with the wishes of the user. After clicking OKBtn will create a folder on the local package matches the name typed earlier.

XAML:

<AppBarButton x:Name="createBtn" Icon="Folder" Label="Tambah Folder" Foreground="White" Click="createBtn_Click"/>
1

There are 1 answers

3
Rob Caplan - MSFT On

You can't create a folder in the application package. The app package is read only and shared amongst users.

If you want to have the user choose a folder then use a FolderPicker and let the user choose a folder anywhere she has access. Save the returned StorageFolder in a FutureAccessList so that the app can access it later without the user having to pick it again.

See Quickstart: Accessing files with file pickers for examples.

We'll need a StorageFolder to track the folder the user picked, and a token to identify the item in the FutureAccessList so it can be retrieved later.

StorageFolder folder;
string accessToken;

And a quick code snippet to pick and remember the folder:

FolderPicker fp= new FolderPicker();
fp.FileTypeFilter.Add(".txt");

folder = await fp.PickSingleFolderAsync();
if (folder != null)
{
   accessToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(folder);
}