public void LocationTemperaturesCsvStartEnd(int locationId, DateTime startDate, DateTime endDate) { Location location = ClassFunctions.ReadLocation(locationId); Watershed watershed = ClassFunctions.ReadWatershed(location.WatershedID); string formattedLocationName = ClassFunctions.FormatForFileSystem(location.SensorName); string formattedWatershedName = ClassFunctions.FormatForFileSystem(watershed.WatershedName); string csvFileName = $"{formattedWatershedName}-{formattedLocationName}_{startDate.ToString("MMddyyyy")}-{endDate.ToString("MMddyyyy")}.csv"; DataSet temperatureDataset = ClassFunctions.GetTemperaturesByLocationIdStartEnd(locationId, startDate, endDate); List <Temperature> temperatureList = new List <Temperature>(); for (int i = 0; i < temperatureDataset.Tables[0].Rows.Count; i++) { DataRow dataRow = temperatureDataset.Tables[0].Rows[i]; Temperature t = new Temperature(); t.Timestamp = Convert.ToDateTime(dataRow["Timestamp"]); t.Celsius = Convert.IsDBNull(dataRow["TempC"]) ? double.NaN : Convert.ToDouble(dataRow["TempC"]); t.Fahrenheit = Convert.IsDBNull(dataRow["TempC"]) ? double.NaN : Convert.ToDouble(dataRow["TempF"]); temperatureList.Add(t); } byte[] allTempDataBytes = DataProcessor.CreateCsvAsBytesNoLocation(temperatureList); Context.Response.Clear(); Context.Response.ContentType = "application/force-download"; Context.Response.AddHeader("content-disposition", "attachment; filename=" + csvFileName); Context.Response.BinaryWrite(allTempDataBytes); Context.Response.End(); }