如何打开 WPF 内容流?
这是代码片段
String str= ??????? // I want to assign c:/my/test.html to this string
Uri uri= new Uri (str);
Stream src = Application.GetContentStream(uri).Stream;
执行此操作的正确方法是什么?我收到“URI notrelative”异常抛出
Here's the code snippet
String str= ??????? // I want to assign c:/my/test.html to this string
Uri uri= new Uri (str);
Stream src = Application.GetContentStream(uri).Stream;
What's the correct way to do this? I'm getting "URI not relative" Exception thrown
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的问题特定于 WPF。请参阅
Application.GetContentStream
方法。您将看到此方法需要相对 URI。请参阅“WPF 应用程序、资源、内容和数据文件”。
Your problem is specific to WPF. See the
Application.GetContentStream
method.You'll read that this method requires a relative URI. See "WPF Application, Resource, Content and Data files".
您有一个文件路径 - 如果您想将其设为 URI,请添加“file:///”,即。 “文件:///c:/my/test.html”
You have a file path - if you want to make it a URI add "file:///", ie. "file:///c:/my/test.html"
对于本地文件 URI,您需要为其添加前缀:
For local file URIs, you need to prefix it with:
我想你会发现你的问题是 Application.GetContentStream 用于位于指定 Uri 的内容数据文件的资源流。也就是说,与可执行程序集一起部署。
如果您查看:http://msdn。 microsoft.com/en-us/library/aa970494(VS.90).aspx#Site_of_Origin_Files
您应该发现上述 file:/// 语法是正确的...但是如果您要打开它们,您可能需要某种开关来确定如何获取流:
同样,如果它是一个 Web URI:
希望有所帮助。
安德鲁.
I think you'll find your problem is that Application.GetContentStream is for a resource stream for a content data file that is located at the specified Uri. That is, deployed alongside an executable assembly.
If you look at: http://msdn.microsoft.com/en-us/library/aa970494(VS.90).aspx#Site_of_Origin_Files
You should find that the file:/// syntax as stated above is correct... But if you're going to open them you'll probably want some kind of switch to work out how to get the stream:
And similarly if it's a web URI:
Hope that helps.
Andrew.