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...
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With