在 WP7 中加载文本文件的 URI 是什么?
使用相对 uri 路径在 WP7 中显示任何图像非常简单。 但加载文本文件就成了一个大问号。
请查看图像并尝试帮助 URI 应该如何将文件作为字符串变量。
Dim S As String
Dim U As New Uri("file:///Family_christmas;component/database/de/1.txt", UriKind.Absolute)
Dim sr As New IO.StreamReader(U.LocalPath, System.Text.Encoding.Unicode)
S = sr.ReadToEnd
sr.Close()
Me.Title = S.Split(Environment.NewLine)(0)
Me.Text = S.Substring(Me.Title.Length + Environment.NewLine.Length)
* 以此方式解决*
将文件声明为资源而不是内容。然后使用以下代码:
Dim S As String
Dim U As New Uri("database/de/1.txt", UriKind.Relative)
Dim streamInfo As Windows.Resources.StreamResourceInfo = Application.GetResourceStream(U)
Dim sr As New IO.StreamReader(streamInfo.Stream, System.Text.Encoding.Unicode)
S = sr.ReadToEnd
sr.Close()
It so simple to show any image in WP7 using relative uri path.
But loading a text file becomes a big questionmark.
Please look at the image and please try to help how the URI should looks like to have the file as string variable.
Dim S As String
Dim U As New Uri("file:///Family_christmas;component/database/de/1.txt", UriKind.Absolute)
Dim sr As New IO.StreamReader(U.LocalPath, System.Text.Encoding.Unicode)
S = sr.ReadToEnd
sr.Close()
Me.Title = S.Split(Environment.NewLine)(0)
Me.Text = S.Substring(Me.Title.Length + Environment.NewLine.Length)
* SOLVED THAT WAY *
Declare file as ressource not as content. Then use the following code:
Dim S As String
Dim U As New Uri("database/de/1.txt", UriKind.Relative)
Dim streamInfo As Windows.Resources.StreamResourceInfo = Application.GetResourceStream(U)
Dim sr As New IO.StreamReader(streamInfo.Stream, System.Text.Encoding.Unicode)
S = sr.ReadToEnd
sr.Close()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
StreamReader
在文件系统中查找文件,而不是在资源中查找文件。您可以通过将您的文本文件标记为资源并使用以下代码来获取资源流:(抱歉将 vb 转换为 c# :))这对我有用。
By default
StreamReader
looks for the file in the file system, not in resources. You can get a resource stream my marking your text file as Resource and using this code: (sorry for the vb to c# conversion :))This worked for me.