在 UWP 中创建文件/文件夹 [英] Creating a file/folder in UWP

查看:36
本文介绍了在 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.

我终于完成了我的通用 Windows (10) 应用程序在 LocalState 文件夹中为用户创建了一个项目文件夹,但只要它留在那里就可以了.现在,我正在尝试生成一些简单的文本文件并保存在Project"文件夹中,示例路径为:LocalState\Project1\example.txt.

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. Now, I'm trying to generate some simple text file and save in "Project" folder, example path: LocalState\Project1\example.txt.

我尝试使用以下代码:

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

但它只保存到 LocalState 目录,也许有一个简单的解决方案,将路径添加到子文件夹,但到目前为止我没有成功.

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.

对不起,我的英语不好,感谢您的所有时间

Sorry for my poor english and thanks for all your time

祝大家天天开心

推荐答案

首先,我们可以制作项目文件夹:

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");

这篇关于在 UWP 中创建文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆