可能重复:
从C#中的URI字符串获取文件名
如何从C#中的Uri中提取文件名?
例如,我有一个Uri
"http://audacity.googlecode.com/files/audacity-win-2.0.exe"
Run Code Online (Sandbox Code Playgroud)
但是如何提取文件名
"audacity-win-2.0.exe"
Run Code Online (Sandbox Code Playgroud)
并将其保存为字符串?
谢谢,
杰瑞
怎么样
Path.GetFileName(string path);
Run Code Online (Sandbox Code Playgroud)
在您的情况下,您应该首先检查它是否是一个文件.
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);
Run Code Online (Sandbox Code Playgroud)
Path.GetFileName
可以做到...
Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
Path.GetFileName(u.AbsolutePath);
Run Code Online (Sandbox Code Playgroud)