[英]Access file from the app folder in uwp
Directory: 目录:
App1
- MainPage.xaml.cs
- Sample.xaml
im trying to do is getting the xaml content from the sample as a string but it doesnt work since it cant find the file: 我试图做的是从样本中获取xaml内容作为字符串,但是由于找不到文件,因此无法正常工作:
var x = Path.GetFullPath(@"sample.xaml");
FileStream s = new FileStream(x, FileMode.Open);
How can I fix this? 我怎样才能解决这个问题?
源文件(.xaml,.cs)已编译,在已部署的应用程序中,它们不作为物理文件存在,因此无法以这种方式打开它们。
I haven't tried this give it a try. 我没有尝试过尝试一下。
Save your file in a location eg (Assets Folder)Now, make sure that the build action is set to Content.
将文件保存在例如(资产文件夹)的位置。现在,确保将构建操作设置为“内容”。
var storageFile = await StorageFile.GetFileFromApplicationUriAsync(
new Uri("ms-appx:///Assets/youfile.xaml"));
The StorageFile you get is of course read-only, but it can be passed to any API that expects a StorageFile. 您获得的StorageFile当然是只读的,但是可以将其传递给需要StorageFile的任何API。
If you want to read you can try. 如果您想阅读,可以尝试。
var result = storageFile.OpenReadAsync()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.