Creating a file/folder in UWP

谁都会走 提交于 2019-12-25 08:47:52

问题


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

Sorry for my poor english and thanks for all your time

Wish you all nice day


回答1:


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


来源:https://stackoverflow.com/questions/40389489/creating-a-file-folder-in-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!