开发者

asp.net how to get image url file name

开发者 https://www.devze.com 2023-03-31 19:20 出处:网络
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

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消