473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Can not Modify web.config file

3
Hi
I am creating installer for asp.net

i am using this code for to modify web.config file
but i cant whats wrong this code

Expand|Select|Wrap|Line Numbers
  1. ' Get configuration.
  2.         Dim config As Configuration = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath)
  3.  
  4.         ' Find app setting to change
  5.         Dim element As KeyValueConfigurationElement = CType(config.AppSettings.Settings("ConnectString"), KeyValueConfigurationElement)
  6.         If Not element Is Nothing Then
  7.             element.Value = strCon
  8.         End If
  9.         config.Save()
Apr 7 '09 #1
4 2957
tlhintoq
3,525 Expert 2GB
What error message are you getting?
Apr 7 '09 #2
pasam
3
I didnt get any eroor message when i instaling.

but no modification in web.config file.
Apr 7 '09 #3
Frinavale
9,735 Expert Mod 8TB
You need to load the web.config into memory before you can modify it.
It's probably a good idea load it as an XmlDocument so that you can parse it easily and edit the key that you want to.

For example:
Expand|Select|Wrap|Line Numbers
  1.  
  2. 'The webConfigLocation variable should be the path to the web.config file.
  3.   Dim webConfigLocation As String = "C:\MyWebAppPath\web.config"
  4.   Dim webConfigDoc As New XmlDocument
  5.   webConfigDoc.Load(webConfigLocation)
  6.   Dim appConfigList As XmlNodeList = webConfigDoc.GetElementsByTagName("add")
  7.  
  8.    For Each appConfigElement As XmlNode In appConfigList
  9.       Dim key As String
  10.       If Not appConfigElement.Attributes("key") Is Nothing Then
  11.          key = appConfigElement.Attributes("key").Value
  12.  
  13. 'Where "DatabaseConnection" is the name of the key for your Connection String
  14.          If String.Compare(key, "DatabaseConnection", True) = 0 Then
  15.             appConfigElement.Attributes("value").Value = "Some Edited Value"
  16.             Exit For
  17.          End If
  18.       End If
  19.    Next
  20.    webConfigDoc.PreserveWhitespace = True
  21.    webConfigDoc.Save(webConfigLocation)
Apr 7 '09 #4
pasam
3
Thnaks for your code

I will try this
Apr 8 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: justin | last post by:
I have the problem that I need to programatically add new url mappings to the web.config file in an asp 2.0 app. e.g. my code is Dim urlMappings As UrlMappingCollection =...
5
by: Alberto | last post by:
I need to modify a value in the app.config file with this code: System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); string key =...
2
by: 3471Jack329 | last post by:
This is a stupid question but I risk it. Just in case something is possible... How can I modify the web.config settings from ASP.NET programming? <system.net> <mailSettings> <smtp...
1
by: =?Utf-8?B?Q2h1Y2sgUA==?= | last post by:
I have an asp.net solution with a web deployment project. When we try to build/debug, we get the message: An editor or project is attempting to check out a file that is modified in memory,...
1
by: dhochee | last post by:
I understand that settings stored in the app.exe.config file and accessed via Properties.Settings.Default are only available within an app domain, but I'm confused about the best way to handle...
3
by: Jeff | last post by:
I have a solution with two projects. Project A is the startup project, while Project B serves as the project with the data logic. At run time, the first thing I need to do is write to Project...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgRGVzYXJyb2xsbw==?= | last post by:
Hi misters, i have an app.config of my App that uses WCF. I need change the configuration servicemodel, and I want update somes values.
6
by: Ramesh | last post by:
Hello, I am using the ofstream class to create a text file with keys and values like: Key1=Value10 Key2=Value15 Key3=Value20 In case I need to set a new value for Key2, say value50 - I am...
5
by: ziycon | last post by:
I have two PHP files, modify.php & config.php, I have the below code in config.php and I'm wondering how I would go about searching config.php from modify.php and changing the values in config.php? ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.