There has got to be a better way to do this. I have a method which returns either your standard "01/01/2014" Date or "January 1st, 2014" Date of the assembly file write time. Any suggestions on streamlining would be much appreciated.
// Grab the last date of revision of the assembly file write time
// You may pass any value 1-2
// 1 will return format MM/dd/YYYY
// 2 will return format MonthName Day-nth, Year
public static string RevisionDate(int id = 0)
{
System.IO.DirectoryInfo Root = new System.IO.DirectoryInfo(HttpContext.Current.Server.MapPath("~"));
Assembly Assy = Assembly.GetExecutingAssembly();
string[] AssyFullName = Assy.FullName.Split(',');
string Title = AssyFullName[0];
string Path = null;
if (Root.ToString().Length - 1 != ('/'))
{
Path = Root.ToString() + "\\bin\\" + Title + ".dll";
}
else
{
Path = Root.ToString() + "bin\\" + Title + ".dll";
}
var ModifiedDate = System.IO.File.GetLastWriteTime(Path);
switch (id)
{
case 1:
return Convert.ToDateTime(ModifiedDate).ToString("MM/dd/yyyy");
case 2:
string MonthName = Convert.ToDateTime(ModifiedDate).ToString("MMMM", CultureInfo.InvariantCulture);
string Day = Convert.ToDateTime(ModifiedDate).ToString("dd");
string Year = Convert.ToDateTime(ModifiedDate).ToString("yyyy");
//eliminate leading zeros from Day
if (Day[0] == '0')
{
Day = Day[Day.Length - 1].ToString();
}
// Beautify String
string nth = string.Empty;
switch (Day[Day.Length - 1])
{
case '1':
nth = "st";
break;
case '2':
nth = "nd";
break;
case '3':
nth = "rd";
break;
default:
nth = "th";
break;
}
return MonthName + " " + Day + nth + ", " + Year;
default:
return "You must provide a format value 1 or 2";
}
}