0

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.

Isma
  • 14,604
  • 5
  • 37
  • 51
Dinesh
  • 67
  • 9

2 Answers2

1

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

Sean
  • 60,939
  • 11
  • 97
  • 136
1

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);
KiwiJaune
  • 530
  • 2
  • 16
  • I already tried this. But business preferred downloading file from url – Dinesh Apr 23 '19 at 08:06
  • 1
    Isn't "String url = "http://test/todaydate" + dateString + ".csv";" the URL the business is looking for ? – KiwiJaune Apr 23 '19 at 08:09
  • Yes that is but sometimes, API doesn't show today's date. It means file might not have uploaded. In such case, package will fail – Dinesh Apr 23 '19 at 08:41
  • So if you don't know the filename, I suggest this solution : https://stackoverflow.com/a/124522/11202463 – KiwiJaune Apr 23 '19 at 08:51
  • Thanks. How to check If file available or not on URL? Let's say, for some reason, today file not uploaded. How to check that? – Dinesh Apr 24 '19 at 10:09
  • Can client.downloadfile(url,localpath) return false if not succeded ? – KiwiJaune Apr 24 '19 at 12:11