我怎样才能获得大会最后修改日期? [英] How can I get the assembly last modified date?

查看:230
本文介绍了我怎样才能获得大会最后修改日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想渲染(用于内部调试/信息)装配的最后修改日期,这样我就知道,当某个网站部署。

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?

我得到这样的版本:

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.

推荐答案

我将第二pYrania的回答是:

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.

这篇关于我怎样才能获得大会最后修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆