mpen
mpen

Reputation: 282995

How to get base filename without query portion?

Given a file path URL such as http://example.com/video.flv?start=5, I want to get out video.flv.

Path.GetFileName("http://example.com/video.flv?start=5") yields video.flv?start=5, which is more than I want. I can't find anything relevant in the Uri class either. Am I missing something?

Upvotes: 1

Views: 182

Answers (2)

Nick Babcock
Nick Babcock

Reputation: 6141

Using Uri.AbsolutePath I was able to achieve the desired results.

Uri t = new Uri("http://example.com/video.flv?start=5");
Console.WriteLine(t.AbsolutePath);
Console.ReadLine();

printed /video.flv

Upvotes: 0

James Manning
James Manning

Reputation: 13579

Various ways, but one option:

new Uri("http://example.com/video.flv?start=5").Segments.Last()

Upvotes: 6

Related Questions