Hi everyone,
Im trying to set a string value to equal the path of the executing .dll called when I instantiate an object from that class. This class is used to read and write values to a config file for an application.
I instantiate it from various access points throughout the application to get and set these properties. In the constructor however, I check to see if the config file exists and, if it doesnt, I create a new one with default values. Currently I am using the follwing syntex for this:
Private FileLocation As String = Environment.CurrentDirectory & "\configfile.xml"
Sub New()
Dim thefile As FileInfo = New FileInfo(FileLocation)
If Not (thefile.Exists) Then LoadDefaultValues()
Try
configfile.Load(FileLocation)
Catch e As Exception
Console.WriteLine("Exception: {0}", e.ToString())
End Try
LoadAllValues()
FileLocation = m_appdirectory
End Sub
The problem I have is when I instantiate a new object of this class from a directory other than where the .dll is, it always creates the configfile.xml file in that directory. I cant hardcode it into the FileLocation path because the user will determine the installation directory.
Thus, is there a way, using reflection or some other technique, to set the file location to always be the current directory of the .dll that is being called?
thanks in advance.
inzo
Im trying to set a string value to equal the path of the executing .dll called when I instantiate an object from that class. This class is used to read and write values to a config file for an application.
I instantiate it from various access points throughout the application to get and set these properties. In the constructor however, I check to see if the config file exists and, if it doesnt, I create a new one with default values. Currently I am using the follwing syntex for this:
Private FileLocation As String = Environment.CurrentDirectory & "\configfile.xml"
Sub New()
Dim thefile As FileInfo = New FileInfo(FileLocation)
If Not (thefile.Exists) Then LoadDefaultValues()
Try
configfile.Load(FileLocation)
Catch e As Exception
Console.WriteLine("Exception: {0}", e.ToString())
End Try
LoadAllValues()
FileLocation = m_appdirectory
End Sub
The problem I have is when I instantiate a new object of this class from a directory other than where the .dll is, it always creates the configfile.xml file in that directory. I cant hardcode it into the FileLocation path because the user will determine the installation directory.
Thus, is there a way, using reflection or some other technique, to set the file location to always be the current directory of the .dll that is being called?
thanks in advance.
inzo