Having used web.config and app.config files for many years, today I learnt something new about them. You can split them into multiple files!
This can be especially handy if your configuration files are getting too big. Splitting them is very straight forward and I will show you how to move your connection strings into a new file.
The first thing to do is open you config file and find the <connectionString> node:
<connectionStrings> <add name="ConnectionString1" connectionString="Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;" providerName="System.Data.SqlClient" /> <add name="ConnectionString2" connectionString="Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;" providerName="System.Data.SqlClient" /> </connectionStrings>
Copy this, including the <ConnectionString> tags and paste it into a notepad, then save it next to your web.config file, calling it ConnectionStrings.config
Update the original config file so it knows it has been split:
<connectionStrings configSource="ConnectionStrings.config" />
That’s it. Your configuration file has been split into multiple files.