如何从我的Windows应用商店应用项目中的资产文件夹中获取文件?
我试图创建在Windows应用商店的应用程序中,我必须存储在一个JSON文件的联系人电话簿应用程序。我想从项目的Assets文件夹创建并访问该Json文件。如何从我的Windows应用商店应用项目中的资产文件夹中获取文件?
我曾尝试以下(都未上班):
Create, Write, and Read a file - Microsoft
Jerry Nixon's Blog about Reading and Writing from Files
和许多其他...
我曾尝试以下代码:
StorageFile SFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Data.txt"));
var display = new Windows.UI.Popups.MessageDialog(SFile.Path);
await display.ShowAsync();
如果有人可以建议我做这件事的方式。谢谢 !
尝试在Package.appxmanifest
文件的应用程序,打开文件添加.txt
文件类型支持的文件类型,并转到宣言标签然后在可用宣言的Dropbox选择此项>*文件类型关联***是点击后***添加*然后在支持的文件类型部分填写内容类型和文件类型,然后单击新建按钮,之后,当操作合作完整,保存更改。
你也可以手动点击右键上查看代码Package.appxmanifest
文件点击添加它,然后下面写一段代码在应用标签:
<Extensions>
<uap:Extension Category="windows.fileTypeAssociation">
<uap:FileTypeAssociation Name="txt">
<uap:DisplayName>.txt</uap:DisplayName>
<uap:EditFlags AlwaysUnsafe="true" />
<uap:SupportedFileTypes>
<uap:FileType ContentType="txt/json">.txt</uap:FileType>
</uap:SupportedFileTypes>
</uap:FileTypeAssociation>
</uap:Extension>
</Extensions>
它提供了一个错误“命名空间前缀'uap'未定义”。 ! –
仍从文件中读取的bin>调试> APPX>资产 –
@ZaryabWaseem你有什么项目类型?它是通用的吗? –
它看起来像路径是错误的:“MS-APPX :///Assets/Data.txt“ – jdweng
我在两个路径中看不到任何区别。 @jdweng –
那条路怎么了? @jdweng –