I have the following code that returns a .CSV file when a link is clicked for a user to save:
public FileContentResult DownloadCSV()
{
StringBuilder sb = new StringBuilder();
var props = typeof(PenCalcModel).GetProperties();
var penSummary = PenSummaryReport(new DateTime(DateTime.Today.Ticks, DateTimeKind.Utc), new DateTime(DateTime.Today.AddDays(1).Ticks, DateTimeKind.Utc), "");
foreach (PenCalcModel item in penSummary)
{
sb.Append(string.Join(",", props.Select(p=>p.GetValue(item,null).ToString())));
sb.AppendLine();
}
return File(new System.Text.UTF8Encoding().GetBytes(sb.ToString()), "text/csv", "PenReport.csv");
}
Is there a way where I could set it up to have this exact same .CSV file exported from the server to a networked drive every X hours?
Having anything set as a scheduled task/job should not be the responsibility of a web app. The app could be recycled at any time and could even interrupt that job. Those kinds of implementations should be the responsibility of a windows service or some sort of task based job on the server. Short answer, don’t do this in the web app.