Laurent Resman
Laurent Resman

Reputation: 133

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. 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

Upvotes: 0

Views: 4521

Answers (1)

UtopiaLtd
UtopiaLtd

Reputation: 2590

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

Upvotes: 5

Related Questions