简体   繁体   中英

Get file name from url using c# or download file from url without specifying filename

I'm using script component. I want to download csv file which is part of url - http://test/todaydate04232019.csv

This part:04232019 of file name is date so it will change daily.

I have used code

client.downloadfile(url,localpath)

It is working fine but when i exclude filename in url, it's not working.

You can use the UriBuilder class to decompose a Uri into its various parts. The Path property should give you what you want.

Can't you build the path with the date of the day like this ?

        DateTime now = DateTime.Now;
        String dateString = now.Month.ToString("00") + now.Day.ToString("00") + now.Year.ToString("0000");
        String url = "http://test/todaydate" + dateString + ".csv";

        ...

        client.downloadfile(url, localpath);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM