Read file from subfolder of application installation folder

孤街浪徒 提交于 2019-12-01 11:43:19

you can do it in other way, using URI :

using Windows.Storage;
StorageFile file = await StorageFile.GetFileFromApplicationUriAsync("ms-appx:///file.txt");

So in your case it will be:

StorageFile txtfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///myfolder/myfile.txt"));

@"\myfolder\myfile.txt"; if its a network path should be @"\\myfolder\myfile.txt"; If its a local file it needs a drive letter ie.@"c:\myfolder\myfile.txt";

However the documentation for GetFileAsync shows a file in a subfolder would be @"myfolder\myfile.txt"

When you use a filename without a subfolder it will look in the current folder.

I think you need to use:

string txtFileName = @".\myfolder\myfile.txt";

The dot in the filename represents the current folder. In you want to specify using relative paths, then @"\myfolder\myfile.txt" is not correct.

GetFileAsync will take relative path in form folder/fileName. You can also get folder first and than file or use GetItemAsync

StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
// Get a file from a subfolder of the current folder
// by providing a relative path.
string image = @"Assets\Logo.scale-100.png";
var logoImage = await appFolder.GetFileAsync(image);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!