I have a custom module where I need to create a file and download it on form submission. So far, I managed to created the file and save it in public folder, but I cannot find a way to download it to client. This is the code I wrote so far.
public function submitForm(array &$form, FormStateInterface $form_state) {
$file_name = $date.'-event.ics';
$cal_file = file_unmanaged_save_data('file content',"public://cal/$file_name",FILE_EXISTS_RENAME);
return new RedirectResponse(file_create_url("public://cal/211443-event.ics"));
}