This topic is locked
[SOLVED]

DATE AND TIME THE EXPORT FILE

8/15/2025 12:39:15 PM
ASPRunner.NET General questions
M
max benelli author

HI EVERYONE, I NEED HELP TO ENTER THE DATE AND TIME WHEN THE EXPORT FILE IS GENERATED.
I HAD ALREADY ASKED THIS,
BUT I CAN'T FIND THE EXACT CODE AND I DON'T EVEN KNOW IN WHICH EVENT IT SHOULD BE ENTERED.
I'M ASKING FOR THE CODE.
I REALLY NEED IT.
ANYONE WHO CAN HELP ME, I'D BE VERY GRATEFUL

ChatGPT 8/15/2025

Certainly! In ASPRunner.NET, if you want to include the date and time when an export file is generated, you typically need to customize the export functionality. Here’s how you can do it:

  1. Locate the Event: The best place to add your custom code is in the Before Export event. This event is triggered just before the export file is created.


  2. Add Custom Code: You can add code to this event to include the date and time in the filename or in the exported content itself.



Here is an example of how you could modify the export filename to include the current date and time:

protected void BeforeExport()
{
// Get the current date and time
string currentDateTime = DateTime.Now.ToString("yyyyMMdd_HHmmss");

// Modify the export filename
string originalFileName = this.ExportFileName;
this.ExportFileName = $"{originalFileName}_{currentDateTime}";

// Optionally, you can also include the date/time in your exported data
// For example, adding it as a header in the exported file
this.AddExportHeader("Exported on: " + DateTime.Now.ToString("f"));
}

Steps to Implement:

  1. Open your ASPRunner.NET project.
  2. Go to the "Events" section in the project editor.
  3. Find the Before Export event.
  4. Add the provided code (or modify it as needed) to include the date/time in the export.

Notes:

  • Adjust the date format in DateTime.Now.ToString("yyyyMMdd_HHmmss") as needed to match your requirements.
  • Make sure to test the functionality after implementing the code to ensure that the export works as intended and the filename or content is formatted correctly.

If you have any specific requirements or additional questions, feel free to ask!

C
Chris Whitehead 8/15/2025

Are you wanting the date and time in the filename or in a log?

C
Chris Whitehead 8/16/2025

If you want to rename and add the datetime to the filename then maybe this might help a little. Put this in the beforeProcessExport event.

### build the filename
$filename = $pageObject->tName . "_" . date('Ymd_His');

### send with desired name + extension
header('Content-Disposition: attachment; filename="'.$filename.'.csv"');

There's also this from afew years ago but it should still work with a tweak or two.

https://asprunner.com/forums/topic/17015-script-to-rename-export-csv-file

M
max benelli author 8/16/2025

Hi, both ways would work.
But sorry, I'm ignorant.
I don't understand anything about events.
My file is called admin_users.csv.

The date is in this format: dd/mm/yyyy.

Could you please provide me with a ready-made source file that I can copy and paste, especially since my English isn't great?
Thanks everyone.

M
max benelli author 8/16/2025

Hi, both ways would work.
But sorry, I'm ignorant.
I don't understand anything about events.
My file is called admin_users.csv.

The date is in this format: dd/mm/yyyy.

Could you please provide me with a ready-made source file that I can copy and paste, especially since my English isn't great?
Thanks everyone.

C
Chris Whitehead 8/16/2025

Max, I can't provide a ready made source file as it's code in the beforeProcessExport event., I'll try and show you with pictures. You state your table is admin_users, the demo table is called todo_lists so don't let that confuse you..
img alt

As shown In the picture you need to be on the events section which is accessed by the dropdown in the centre at the bottom of phprunner.

Then, when in the events section, on the left hand tree menu(highlighted), you need to navigate to your admin_users export page, then "Export page : Before process"(highlighted) this is where you paste the code.

This is the code you'll need to paste into the event.

### build the filename
$filename = $pageObject->tName . "_" . date('d_m_Y');

### send with desired name + extension
header('Content-Disposition: attachment; filename="'.$filename.'.csv"');