asp.net how to get image url file name
If the user provides the url path to the image, i want to be able to try and dow开发者_StackOverflow中文版nload it with with a Webclient. I am using a httpresponse to check the file. Is there a way to grab the file name to make it easier to save? Thanks
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();
I would look into using System.IO.Path.GetFileName for this:
string fileName = Path.GetFileName("http://www.abc.com/myimage.jpg");
精彩评论