void SaveKurByDayAsync(DateTime firstDay , DateTime lastDay)
{
List<DateTime> dateList = new();
for (DateTime date = firstDay; date <= lastDay; date = date.AddDays(1))
{
dateList.Add(date);
}
foreach (DateTime date in dateList)
{
string day = date.Day.ToString();
string year = date.Year.ToString();
string month = date.Month.ToString();
if (int.Parse(month) < 10)
month = "0" + month;
if (int.Parse(day) < 10)
day = "0" + day;
string format = null;
if (date == DateTime.Today)
format = "https://www.tcmb.gov.tr/kurlar/today.xml";
format = "https://www.tcmb.gov.tr/kurlar/" + year + month + "/" + day + month + year + ".xml";
List<XElement> exchangeList = XElement.Load(format).Elements().ToList();
foreach (XElement exchangeItem in exchangeList)
{
Console.WriteLine(decimal.Parse(exchangeItem.Element("ForexBuying").Value, NumberStyles.Number, CultureInfo.InvariantCulture));
}
}
}
I have a method that gets exchange rate information published in xml format every day. But on public holidays xml is not published here and I get NotFound error in 'Load' method. I want to skip that day and move on to the next day, but I couldn't figure it out.