MilkBottle
MilkBottle

Reputation: 4332

How to get a file from KnownFolder.DocumentsLibrary

I need some help on File and Folders operations.

I need to retrieve a file in subfolder in a main Folder in the Document Library.

Let say, I create the following folder and subfolder in Documents Folder:

  1. I create a main Folder with name : MyWorkShop
  2. In the Main Folder : MyWorkShop , I create a SubFolder in it and name it : 2016-08-10
  3. in the Subfolder there is a file myfile.txt

Is Document Library Folder refer to the Documents Folder in C-drive?

How to I retrieve the file in the Subfolder ?

Below is my current code, how to start from here?

StorageFolder storageFolder = KnownFolders.DocumentsLibrary;

StorageFile sampleFile = await storageFolder.GetFileAsync("myfile.txt");

Upvotes: 1

Views: 379

Answers (1)

Bart
Bart

Reputation: 10015

KnownFolders.DocumentsLibrary references normally to %USERPROFILE%\Documents (see MSDN).

You have to load each subfolder before being able to access the file.

StorageFolder storageFolder = KnownFolders.DocumentsLibrary;
StorageFolder mainFolder = await storageFolder.GetFolderAsync("MyWorkShop");
StorageFolder subFolder = await mainFolder.GetFolderAsync("2016-08-10");
StorageFile sampleFile = await subFolder.GetFileAsync("myfile.txt");

Upvotes: 1

Related Questions