[英]URI formats are not supported exception
我是新手,所以我尝试打开一个文件。 这是代码:
string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
string filenamelocation = System.IO.Path.Combine(path, "Fix_DeltaPro.exe");
System.Windows.MessageBox.Show(""+filenamelocation+"");
using (FileStream stram = File.Open(filenamelocation, FileMode.Open)) ;
但是有一点错误:“不支持URI格式。”请帮助我:)
CodeBase
是在其中找到程序集的Uri。 这可以是文件file://
,网址http://
或其他位置 。
在文件实例中,获取Uri的AbsolutePath
。
var codeBaseUri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
var path = Path.GetDirectoryName(codeBaseUri.AbsolutePath);
var filenamelocation = Path.Combine(path, "Fix_DeltaPro.exe");
MessageBox.Show(filenamelocation);
using (var stream = File.Open(filenamelocation, FileMode.Open)) ;
由于可以从不同的位置加载CodeBase
因此请使用Assembly.Location
获取从磁盘加载程序集的位置。
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var filenamelocation = Path.Combine(path, "Fix_DeltaPro.exe");
MessageBox.Show(filenamelocation);
using (var stream = File.Open(filenamelocation, FileMode.Open)) ;
也可以看看:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.