2013-03-30 75 views
-2

我有這樣的代碼刪除文件:///之前的文件夾路徑

string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); 

這將產生一個字符串,如

"file://C://Foo//bin" 

我要的是

"C://Foo//bin" 

怎麼辦我得到這個,而不是從手動開始刪除"file://"

+0

很抱歉,如果我完全誤會,但不Application.StartupPath得到你所需要的? – Dan

+0

'path = path.Replace(「file://」,「」)''。 – leppie

+0

「手動」刪除它有什麼問題? –

回答

0

使用的串

  string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase); 
     this.Text = path.Substring(6, path.Length - 6); 

或使用該

this.Text = Application.StartupPath; 
+1

OP問他怎麼能實現這一點,而不需要手動刪除它。 –