【发布时间】:2012-06-28 04:52:12
【问题描述】:
如何在 C# 中从 Uri 中提取文件名?
例如,我有一个 Uri
"http://audacity.googlecode.com/files/audacity-win-2.0.exe"
但是如何提取文件名
"audacity-win-2.0.exe"
并将其保存为字符串?
谢谢,
杰瑞
【问题讨论】:
如何在 C# 中从 Uri 中提取文件名?
例如,我有一个 Uri
"http://audacity.googlecode.com/files/audacity-win-2.0.exe"
但是如何提取文件名
"audacity-win-2.0.exe"
并将其保存为字符串?
谢谢,
杰瑞
【问题讨论】:
怎么样
Path.GetFileName(string path);
你的情况
Path.GetFileName(new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe").AbsolutePath);
【讨论】:
Path.GetFileName可以做到……
Uri u = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
Path.GetFileName(u.AbsolutePath);
【讨论】:
例如
Uri uri = new Uri("http://audacity.googlecode.com/files/audacity-win-2.0.exe");
string Path.GetFileName(uri.AbsolutePath);
【讨论】:
假设URI 总是代表物理文件是不安全的,因此不能保证从URI 中提取文件名。
【讨论】: