1

I am currently building a Windows Phone 8 Application but I am struggling with the following problem. Although I can access to any text files on my computer , I cannot access to a text file that I created in the resource folder that I created in my application.

Does anyone know how to access to a textfile in a folder that belongs to the application ande then use the streamReader to read it?

Thank You Very Much For Your Help !

4

1 回答 1

3

您使用 Application.GetResourceStream 方法传入文件的 Uri,以访问返回的 StreamResourceInfo 对象,该对象具有供您访问的 Stream 属性(然后您可以将其传递给 StreamReader 等)。

至于 Uri,它取决于您为此文件设置的构建操作(来自“属性”窗口),即。无论是资源还是内容。

如果它是一个资源,那么 Uri 应该是:

new Uri("/AssemblyName;component/path/file.txt", UriKind.Relative);

如果它是一个内容,那么 Uri 应该是:

new Uri("path/file.txt", UriKind.Relative);

请注意,“AssemblyName”是包含该文件的项目的程序集的名称。并且“路径”是项目中文件的正斜杠分隔路径,考虑到它所在的文件夹和子文件夹。

于 2013-08-02T15:47:20.893 回答