I want to render (for internal debugging/info) the last modified date of an assembly, so I'll know when a certain website was deployed.
Is it possible to get it through reflection?
I get the version like this:
Assembly.GetExecutingAssembly().GetName().Version.ToString();
I'm looking for something similar -- I don't want to open the physical file, get its properties, or something like that, as I'll be rendering it in the master page, and don't want that kind of overhead.
I'll second pYrania's answer:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location);
DateTime lastModified = fileInfo.LastWriteTime;
But add this:
You mention you don't want to access the file system since it's in your master page and you don't want to make that extra file system hit for every page. So don't, just access it once in the Application load event and then store it as an application-level variable.
If you default the Revision and Build Numbers in AssemblyInfo:
[assembly: AssemblyVersion("1.0.*")]
You can get the an approximate build date with:
Version version = typeof(MyType).Assembly.GetName().Version;
DateTime date = new DateTime(2000, 1, 1)
.AddDays(version.Build)
.AddSeconds(version.Revision * 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With