Asp.net how to get image url file name

If the user provides the image path URL, I want to try and download it using the Webclient. I use httpresponse to verify the file. Is there a way to capture the file name to make it easier to save? Thanks

+4
source share
2 answers

Try using the Uri Class to load the path and pull the file name from the Segments collection:

Uri uri = new Uri("http://www.domain.com/image.jpg"); string fileName = uri.Segments.Last(); 
+6
source

I would consider using System.IO.Path.GetFileName for this:

 string fileName = Path.GetFileName("http://www.abc.com/myimage.jpg"); 
+1
source

Source: https://habr.com/ru/post/1369562/


All Articles