简体   繁体   English

不支持URI格式

[英]URI formats are not supported exception

I am new and I try to open a file. 我是新手,所以我尝试打开一个文件。 Here is code: 这是代码:

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)) ;

But have little error : "URI formats are not supported. " Help me please :) 但是有一点错误:“不支持URI格式。”请帮助我:)

The CodeBase is a Uri where the assembly was found. CodeBase是在其中找到程序集的Uri。 This can a file file:// , a web location http:// , or other locations . 这可以是文件file:// ,网址http://或其他位置

In the instance of a file get the AbsolutePath for the Uri. 在文件实例中,获取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)) ;

Since the CodeBase can be loaded from difference places use the Assembly.Location to get the location where the assembly was loaded from disk. 由于可以从不同的位置加载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)) ;

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM