2012-06-28 18 views

回答

6

如何

Path.GetFileName(string path); 

在你的情况,你应该首先检查是否是一个文件。

Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe") 
string filename = string.Empty; 

if (u.IsFile) 
    filename = Path.GetFileName(u.AbsolutePath); 
+0

它会给你没事文件名。 – scegg

+8

这可能是旧的,但对于这个例子,这个方法在文件名上会得到空字符串,因为当你给一个文件时IsFile只有true:// type URI –

0

它是不安全的假设URI总会代表物理文件,因此从URI解压文件名并不总是保证。

2

例如,

Uri uri = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe"); 
string Path.GetFileName(uri.AbsolutePath); 
5

Path.GetFileName可以做到这一点...

 Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe"); 
     Path.GetFileName(u.AbsolutePath);