Wednesday, July 06, 2011

How to Find the Holidays in given date range

I was working with fully date time format around to develop the attendance system.
I need to ignore the Weekend days and other government announced holiday list.
This will used to find the day was a holiday or not in the given date range.
 public DataSet ShowHolidays()
    {

        DataSet ds = new DataSet();
        ds.ReadXml(@"D:\\holiday.xml");
        return ds;
    }
I am maintaining the holiday list xml file

2011/07/04
2011/07/05
2011/07/06

 ArrayList list = new ArrayList();
 public bool IsHolidays(DateTime dt1)
    {
        DataSet d1 = ShowHolidays();
        foreach (DataRow row in d1.Tables[0].Rows)
        {
            list.Add(Convert.ToDateTime(row["Dates_Text"]).ToShortDateString());

        }
        return list.Contains(dt.ToShortDateString());
    }