Howto determine the Modified date of your executable?

  • Thread starter Thread starter Marcel Brekelmans
  • Start date Start date
M

Marcel Brekelmans

Hello,

I know about the FileInfo.LastWriteTime() function. However, this is not
always returning the modified date of the executable that I want: when you
copy the executable to another directory the FileInfo.LastWriteTime()
function returns the copy-time.

I can see in my explorer that there is another modified time, the time when
I compiled the executable. My explorer (explorer2, that is, Zabkat's
dual-pane explorer) shows this timestamp also in the directory to which I
copied the executable, in the 'Modifed' column. So, there must be a field
somewhere that retains the original Modifed date. Does anyone know how to
get that?

What I really want is to have an 'About...' form in my application that
shows the last-build date. So, maybe there's another approach to that?

Regards,
Marcel Brekelmans
 
I googled a nice way:

In your AssemblyInfo.cs file, leave out the Version and Build numbers:

[assembly: AssemblyVersion("1.1.*")]

After the compiler has build the application it has set Build to the number
of days since Jan 1, 2000 and Version to the number of seconds since
midnight (local time) divided by 2. From this information you can retrieve
the build timestamp:

Version v = new Version(Application.ProductVersion);

DateTime t = new DateTime((v.Build - 1) * TimeSpan.TicksPerDay + v.Revision
* TimeSpan.TicksPerSecond * 2).AddYears(1999);

TimeZone localZone = TimeZone.CurrentTimeZone;

DateTime tt = localZone.IsDaylightSavingTime(t) ? t.AddHours(1) : t;

lblBuild.Text = tt.ToString();

v.Build - 1 : the number of days includes the current day. For today however
you must only count the time elapsed specified by Revision
The addHours(), of course, is specific to my timezone.
 
Back
Top