How can I get the assembly last modified date?

juan picture juan · Apr 29, 2009 · Viewed 22.9k times · Source

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.

Answer

Clyde picture Clyde · Apr 29, 2009

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.