簡體   English   中英

不支持URI格式

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM