Skip to content

Instantly share code, notes, and snippets.

@kevinblake
Created October 30, 2012 10:46
Show Gist options
  • Save kevinblake/3979568 to your computer and use it in GitHub Desktop.
Save kevinblake/3979568 to your computer and use it in GitHub Desktop.
Show Assembly Version
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="version.aspx.cs" Inherits="MyApplication.Version" %>
{"Version" : <asp:Literal runat="server" ID="Version"></asp:Literal>, "BuildDate" : <asp:Literal runat="server" ID="BuildDateString"></asp:Literal> }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MyApplication
{
public partial class Version : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.Version.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString();
this.BuildDateString.Text = this.RetrieveLinkerTimestamp().ToString();
}
// Stolen from Joe Spivey (http://stackoverflow.com/questions/1600962/displaying-the-build-date)
private DateTime RetrieveLinkerTimestamp()
{
var filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
const int CPeHeaderOffset = 60;
const int CLinkerTimestampOffset = 8;
var b = new byte[2048];
Stream s = null;
try
{
s = new System.IO.FileStream(filePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
s.Read(b, 0, 2048);
}
finally
{
if (s != null)
{
s.Close();
}
}
var i = System.BitConverter.ToInt32(b, CPeHeaderOffset);
var secondsSince1970 = System.BitConverter.ToInt32(b, i + CLinkerTimestampOffset);
var dt = new DateTime(1970, 1, 1, 0, 0, 0);
dt = dt.AddSeconds(secondsSince1970);
dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);
return dt;
}
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace MyApplication {
public partial class version {
/// <summary>
/// Version control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal Version;
/// <summary>
/// BuildDateString control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Literal BuildDateString;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment