Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get filename and extension and remove query string using substring

Tags:

substring

c#

Hiee guys,

I have several image urls from which i download the data and save it in db. I use (imageurl.Split('/'))[(imageurl.Split('/').Length) - 1]; to create the filename.

Problem is,there are some urls which contains query string. due to which filenames i get for them have pattern imgname.img_type_extension?somefield=somevalue

How can i get filename.extension leaving query string from above substring??

Thanks for stopping by...

like image 288
Milind Anantwar Avatar asked Feb 26 '26 12:02

Milind Anantwar


1 Answers

var path = imageurl.Split('?')[0];
var fileName = Path.GetFileNameWithoutExtension(path);

EDIT : for file name WITH extension just use another method from Path

    var path = imageurl.Split('?')[0];
    var fileName = Path.GetFileName(path);
like image 88
tchrikch Avatar answered Feb 28 '26 02:02

tchrikch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!