从WPF一包URI打开一个文件 [英] Opening a file from a pack URI in WPF

查看:335
本文介绍了从WPF一包URI打开一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找从应用程序包打开.csv文件做一些单元测试。因此,我更喜欢一些模拟 File.ReadAllText(字符串路径)这是不是 X.ReadAllText(URI URI)。我还没有尚未能发现这一点。

I am looking to open a .csv file from the application pack to do some unit testing. So what I would really love is some analog to File.ReadAllText(string path) which is instead X.ReadAllText(Uri uri). I haven't as yet been able to find this.

有谁知道是否有可能阅读的文本/字节(不介意它)从包中的文件,而无需先编译此文件到磁盘?

Does anyone know if it is possible to read text / bytes (don't mind which) from a file in the pack without compiling this file to disk first?

呵呵,并顺便说一句, File.ReadAllText(@包://应用:,,, / S preadSheetEngine /测试/ Example.csv)没科技工作对我来说..和我已经做了 VAR应用=新的应用程序()诱骗,以确保我有一个包开始了我的单元测试过程中。

Oh and btw, File.ReadAllText(@"pack://application:,,,/SpreadSheetEngine/Tests/Example.csv") didn't work for me.. and I am already doing the var app = new Application() trick to make sure I have a pack started up during my unit test.

推荐答案

刚刚获得来自Application.GetResourcePart()返回的流和使用的的StreamReader 使用ReadToEnd成员阅读所有的文字了。

Just get the stream from the Application.GetResourcePart() return value and use a StreamReader to read all the text out using the ReadToEnd member.

这篇关于从WPF一包URI打开一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆