private void GenerateCSV(IEnumerable <ReportContact> reportContacts, string fileName) { if (reportContacts.IsAny()) { Log.Informational("Request received for generating CSV with filename as : " + fileName); string location = _jobConfig.NeverBounceCsvFiles; location += fileName.Replace(".xls", ".csv").Replace(".xlsx", ".csv").Replace(".xml", ".csv"); DataTable table = ConvertToDataTable(reportContacts); ReadExcel ex = new ReadExcel(); byte[] bytes = ex.ConvertDataSetToCSV(table, string.Empty); File.WriteAllBytes(location, bytes); Log.Informational("CSV generated successfully"); } else { throw new UnsupportedOperationException("Couldn't find contacts with email for filename : " + fileName); } }