[英]Create Folder with the folder name as desired user on UWP
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. 单击createBtn后,它将显示一个弹出窗口,供用户根据用户的意愿键入文件夹名称。 After clicking OKBtn will create a folder on the local package matches the name typed earlier. 单击OKBtn后,将在本地包上创建一个与先前键入的名称匹配的文件夹。
XAML: XAML:
<AppBarButton x:Name="createBtn" Icon="Folder" Label="Tambah Folder" Foreground="White" Click="createBtn_Click"/>
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. 如果要让用户选择一个文件夹,请使用FolderPicker并让用户在她有权访问的任何位置选择一个文件夹。 Save the returned StorageFolder in a FutureAccessList so that the app can access it later without the user having to pick it again. 将返回的StorageFolder保存在FutureAccessList中,以便应用程序以后可以访问它,而无需用户再次选择它。
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来跟踪用户选择的文件夹,以及一个令牌来标识FutureAccessList中的项目,以便以后可以检索它。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.