Dim s As String Dim path As String s = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) path = System.IO.Path.GetDirectoryName(s) & "\Layer Files\"
s = path & "Polygon.lyr" pLayerFile = New LayerFile pLayerFile.Open(s) pLayer2 = pLayerFile.Layer pGeoFeatureLayer2 = pLayer2 pGeoFeatureLayer.Renderer = pGeoFeatureLayer2.Renderer pLayerFile.Close()
Public Shared ReadOnly Property AssemblyDirectory() As String Get Dim codeBase As String = Assembly.GetExecutingAssembly().CodeBase Dim uriBuilder As New UriBuilder(codeBase) Dim assemblyPath As String = Uri.UnescapeDataString(uriBuilder.Path) Return Path.GetDirectoryName(assemblyPath) End Get End Property
Private Function GetAssemblyDirectory() As String Dim Codebase As String Dim URI As UriBuilder Dim AssemblyDLLFilePath As String Dim AssemblyDirectory As String Codebase = System.Reflection.Assembly.GetExecutingAssembly().CodeBase URI = New UriBuilder(Codebase) AssemblyDLLFilePath = URI.Path.ToCharArray AssemblyDirectory = System.IO.Path.GetDirectoryName(AssemblyDLLFilePath) AssemblyDirectory = AssemblyDirectory.Replace("%7B", "{") AssemblyDirectory = AssemblyDirectory.Replace("%7D", "}") Return AssemblyDirectory End Function
Why is it that I cant just use the directory string pulled, that I have to replace the %7B with { and %7D as } to get the path to the files pushed along with the addin?
This is what I do...Just never understood why I have to manipulate the string path.
CodeBase is in URI format, so has had certain characters escaped. So it would be better to use the Uri.UnescapeDataString() method to take care of those, rather than just handling the specific ones.
-Jeff