2
  • i have created installer for the web application.
  • i want to change the default connectionstring value in web.config by the connectionstring passed by the user from the installation.
Partha
  • 2,062
  • 6
  • 24
  • 31

1 Answers1

1

A simple way might be to simply Read in the web.config and do a string replace, then write out the web.config again:

eg: in web.config containing:

...
<add name="Application" connectionString="SETUP_CONNECTION_STRING" />
...

replace SETUP_CONNECTION_STRING with actual string:

This assumes its done on initial setup where multiple settings could be set without the need to use the Configuration classes etc.

Mark Redman
  • 24,079
  • 20
  • 92
  • 147
  • Yes, this is what i need? can you tell me how to do this by code? – Partha Sep 01 '09 at 13:24
  • I wont write out ALL the code, but you can use a StreamReader to read a file to a string, do the Replace using String.Replace() and write out the file using FileStream/StreamWriter. – Mark Redman Sep 01 '09 at 13:50