gagangupt16
gagangupt16

Reputation: 231

Retrieve StorageFile with the help of path from Local Folder

I am making Windows 8.1 Universal App and want to retrieve file, (local -> folder -> sub Folder -> file) which is stored in Local Folder.

One way is open Local Folder, then open folder, then open sub folder, then file. But If I know the path, can I simply open the file?

(Like in Windows Phone 8, store.OpenFile())

Is there an API which would return Storage File when passed path?

Example: GetStorageFile("local/folder/subFolder/file") ?

Upvotes: 1

Views: 2061

Answers (2)

Kishor Bikram Oli
Kishor Bikram Oli

Reputation: 1828

string path = ApplicationData.Current.LocalFolder + "\\" + "YourFolder" + "\\" + "YourSubfolder" + "\\yourfile.xml";
StorageFolder folder = ApplicationData.Current.LocalFolder;
StorageFile file = await folder.GetFileAsync(path);

Hope this helps.

Upvotes: 0

Peter Torr
Peter Torr

Reputation: 12019

You can use StorageFile.GetFileFromApplicationUriAsync and pass in a URI such as ms-appdata:///local/folder/subfolder/file.txt. This is preferred over GetFileFromPathAsync (@Parad1s3's suggestion) since it is relative to your data folder and won't change if the location of the app changes (eg, on a phone the user can move to or from the SD card).

Upvotes: 1

Related Questions