Tuesday, December 15, 2009

Formatting International Date

A quick post to help establish the numerical designator for a day, and create a International date in the form (DD(designator) MMMM, yyyy).

Code Snippet
  1. Private Function FormatInternationalDate(ByVal DateToFormat As Date) As String
  2.     Dim NumericalDesignator As String = String.Empty
  3.     Select Case Day(DateToFormat)
  4.         Case Is = 1, 21, 31
  5.             NumericalDesignator = "st"
  6.         Case Is = 2, 22
  7.             NumericalDesignator = "nd"
  8.         Case Is = 3, 23
  9.             NumericalDesignator = "rd"
  10.         Case Else
  11.             NumericalDesignator = "th"
  12.     End Select
  13.     '// Return date as 24th June, 2009
  14.     Return DateToFormat.Day.ToString & NumericalDesignator & Space(1) & DateToFormat.ToString("MMMM, yyyy")
  15. End Function

Monday, December 14, 2009

Locating a file placed in the bin directory when Build Action is set to Content

Task: How could a get a content file from the bin directory without having to hard code the directories that are created under the bin when a project is built. Using reflection I get the Executing Assembly’s Codebase (Note: You could also use Assembly.GetExecutingAssembly().Location then there’s no need for the replace in line 3)

Code Snippet
  1. Dim pathToMyFile As String = String.Empty
  2. With Assembly.GetExecutingAssembly().CodeBase
  3.     Dim tmpPath As String = .Replace("file:///", String.Empty)
  4.     pathToMyFile = tmpPath.Substring(0, tmpPath.LastIndexOf("bin") + 4)
  5.     Dim directoryList() As String = Directory.GetFiles(pathToMyFile, "MyFileName.docx", SearchOption.AllDirectories)
  6.     For Each myFile In directoryList
  7.         pathToMyFile = myFile
  8.     Next
  9. End With

Calling .NET From COM Originally posted by Mikec276 on C Sharp Friends It might be hard to convince your IT manager to let you build y...