[英]What is the URI to load text file in WP7?
It so simple to show any image in WP7 using relative uri path. 使用相对uri路径显示WP7中的任何图像非常简单。 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. 请查看图片,并尝试帮助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)
* 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()
By default StreamReader
looks for the file in the file system, not in resources. 默认情况下,
StreamReader
在文件系统而不是资源中查找文件。 You can get a resource stream my marking your text file as Resource and using this code: (sorry for the vb to c# conversion :)) 您可以通过将文本文件标记为Resource并使用以下代码来获得资源流:(很抱歉,将vb转换为c#:)
StreamResourceInfo info = Application.GetResourceStream(new Uri("file:///Family_christmas;component/database/de/1.txt", UriKind.Relative));
StreamReader reader = new StreamReader(info.Stream, System.Text.Encoding.Unicode);
string text = reader.ReadToEnd();
MessageBox.Show(text);
This worked for me. 这对我有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.