简体   繁体   English

在UWP中创建文件/文件夹

[英]Creating a file/folder in UWP

first of all I really hope I'm not asking already answered question, I did my research on stack overflow and beyond and so far didn't find answer to my question. 首先,我真的希望我不要问已经回答的问题,我对堆栈溢出及以后的内容进行了研究,到目前为止还没有找到我的问题的答案。

I finally accomplished that my Universal windows (10) app makes a project folder for user, inside LocalState folder, but its fine as long as it stays there. 我终于实现了,我的通用Windows(10)应用程序在LocalState文件夹内为用户创建了一个项目文件夹,但是只要它停留在该文件夹中就可以了。 Now, I'm trying to generate some simple text file and save in "Project" folder, example path: LocalState\\Project1\\example.txt. 现在,我试图生成一些简单的文本文件并保存在“ Project”文件夹中,示例路径为:LocalState \\ Project1 \\ example.txt。

I tried with following code: 我尝试使用以下代码:

StorageFolder mapa_projekta = ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await mapa_projekta.CreateFileAsync("sample.txt");

But it only saves to LocalState directory, maybe there is simple solution of adding path to the sub folder, but so far I didn't succeed in that. 但是它只保存到LocalState目录,也许有一个简单的解决方案将路径添加到子文件夹,但是到目前为止,我还没有成功。

Sorry for my poor english and thanks for all your time 对不起,我英语不好,感谢您的宝贵时间

Wish you all nice day 祝大家美好的一天

First, we can make the project folder: 首先,我们可以创建项目文件夹:

StorageFolder rootFolder = ApplicationData.Current.LocalFolder;
var projectFolderName = "Project1";
StorageFolder projectFolder = await rootFolder.CreateFolderAsync(projectFolderName, CreationCollisionOption.ReplaceIfExisting);

Then, you can create your file within your subfolder: 然后,您可以在子文件夹中创建文件:

StorageFile sampleFile = await projectFolder.CreateFileAsync("sample.txt");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM