Author: aspnewbieperson | Posted on: 3/17/2009 7:08:56 PM | Views : 854

I'm attempting to update the web.config file programmatically, however I'm getting an object reference error (Object reference not set to an instance of an object.).


I have label on the page, a textbox, and a button. The label is the appSetting value, and the textbox contains the current value, and is updated when the button is clicked.


My code is as follows:




Protected Sub UpdateConfigValue(ByVal Sender As Object, ByVal E As EventArgs)

Try

Dim strSection As String = lblValueTitle.Text

Dim strValue As String = DeDodgify(tbValue.Text)

Dim strConfig As Configuration = WebConfigurationManager.OpenWebConfiguration("/")

Dim appsetting As AppSettingsSection = strConfig.GetSection("appSettings")

appsetting.Settings(strSection).Value = strValue

strConfig.Save()

Catch Ex As Exception

lblStatus.Text = "ERROR: " & Ex.Messa ...

Go to the complete details ...