可能重复:
如何从C#的Uri中提取文件名?
例如,我有一个Uri
"http://audacity.googlecode.com/files/audacity-win-2.0.exe"
但是如何提取文件名呢?
"audacity-win-2.0.exe"
并将它保存为字符串?
谢谢,
Jerry
可能重复:
如何从C#的Uri中提取文件名?
例如,我有一个Uri
"http://audacity.googlecode.com/files/audacity-win-2.0.exe"
但是如何提取文件名呢?
"audacity-win-2.0.exe"
并将它保存为字符串?
谢谢,
Jerry
Path.GetFileName
来完成此操作:
Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
Path.GetFileName(u.AbsolutePath);
Path.GetFileName(string path);
根据你的情况
Path.GetFileName(new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe").AbsolutePath);
Uri uri = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
string Path.GetFileName(uri.AbsolutePath);
不能安全地假设一个URI
总是代表物理文件,因此从URI
中提取文件名并不总是保证的。