Thursday, November 15, 2012

How to get current assembly version and build time?


        private static string GetAssemblyVersionBuildDate()

        {
            string filePath = System.Reflection.Assembly.GetCallingAssembly().Location;
            const int c_PeHeaderOffset = 60;
            const int c_LinkerTimestampOffset = 8;
            byte[] b = new byte[2048];
            System.IO.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();
                }
            }

            int i = System.BitConverter.ToInt32(b, c_PeHeaderOffset);
            int secondsSince1970 = System.BitConverter.ToInt32(b, i + c_LinkerTimestampOffset);
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);
            dt = dt.AddSeconds(secondsSince1970);
            dt = dt.AddHours(TimeZone.CurrentTimeZone.GetUtcOffset(dt).Hours);

            return "v"+ System.Reflection.Assembly.GetCallingAssembly().GetName().Version.ToString() + " "+ dt.ToString();
        }

How to access session variables from anywhere in ASP.NET?


By full path like this:
System.Web.HttpContext.Current.Session["sessionVarName"];

How to remove local mapping in TFS?

How to remove local mapping in TFS?
1. In team exploerer, Open that folder
2. Go File -> Source Control -> Remove mapping (It is dynamic menu item)

Coexistence of projects between Visual Studio 2010 and 2012

http://weblogs.asp.net/sreejukg/archive/2012/10/17/coexistence-of-projects-between-visual-studio-2010-and-2012.aspx

clip_image001