Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Filename from url in C#

Tags:

c#

.net

Currently we have a solution that grabs the filename from the URL using this

currentFile = Path.GetFileNameWithoutExtension(url);

We found that if there are query strings attached that include characters such as quotes it returns with an error of Illegal characters in path.

For example if the url is

http:\\myurl.com\mypage.aspx?utm_content=This+Is+"Broken"

Then it won't get the filename. Is there a better, cleaner way to get "mypage"?

like image 568
SDC Avatar asked Dec 14 '11 20:12

SDC


1 Answers

use this: Uri.AbsolutePath

Request.Url.AbsolutePath
like image 181
Davide Piras Avatar answered Oct 15 '22 21:10

Davide Piras