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
- Dim pathToMyFile As String = String.Empty
- With Assembly.GetExecutingAssembly().CodeBase
- Dim tmpPath As String = .Replace("file:///", String.Empty)
- pathToMyFile = tmpPath.Substring(0, tmpPath.LastIndexOf("bin") + 4)
- Dim directoryList() As String = Directory.GetFiles(pathToMyFile, "MyFileName.docx", SearchOption.AllDirectories)
- For Each myFile In directoryList
- pathToMyFile = myFile
- Next
- End With
No comments:
Post a Comment