[RESOLVED] [2005] Finding the path of a file during installing
Hello,
I have a webSetup program for installing my web service and I want to change the connection string. As the user will not know the connection string until they install the program. So during the installation the connection string has to be updated.
I have included a installer class and have used the interface with 4 textboxes to get the user input.
The code below works if you know where the web config will be before hand. However, the user will only know this when the program is installed.
Is there a method that will give you this information?
Many thanks in advance,
Steve
Code:
Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
MyBase.Install(stateSaver)
Dim database As String = Me.Context.Parameters.Item("DBName")
Dim server As String = Me.Context.Parameters.Item("Server")
Dim userID As String = Me.Context.Parameters.Item("UserID")
Dim pwd As String = Me.Context.Parameters.Item("pwd")
Dim cnnStr As String = String.Empty
Dim fileMap As New ExeConfigurationFileMap
Dim webConfigPath As String = "C:\where can I find where this is being installed?"
fileMap.ExeConfigFilename = webConfigPath
Dim config As System.Configuration.Configuration
config = System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None)
cnnStr = config.ConnectionStrings.ConnectionStrings("ServiceMasterConnectionString").ConnectionString
MsgBox(cnnStr)
Dim newCnnStr As String
newCnnStr = String.Format("Data source = {0} database = {1} user ID = {2} pwd = {3}", server, database, userID, pwd)
MsgBox(newCnnStr)
config.ConnectionStrings.ConnectionStrings("ServiceMasterConnectionString").ConnectionString = newCnnStr
config.Save()
End Sub
Re: [2005] Finding the path of a file during installing
You know the path of your executable from the [TARGETDIR] installer variable. Pass that to your InstallerClass object and then use the OpenExeConfiguration method.
Re: [2005] Finding the path of a file during installing
Thanks Jmc,
That really worked.
However, I am just wondering instead of using the dialog boxes that the setup gives you to add to the installation. The one I am using only allows you to have up to 4 text boxes.
Is it possible to be able to create your own and add them instead. I would like to customize my installation a little bit more and user interface does not give me that much functionality.
Many thanks for any suggestions,
Steve
Re: [2005] Finding the path of a file during installing
It's not an ideal solution because it makes for a less consistent interface but you can accomplish pretty much anything you want with custom actions. It would have been nice if VS provided a facility to link your own controls into the actual setup wizard UI but it's not that powerful unfortunately.