473,405 Members | 2,379 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,405 software developers and data experts.

read and write to the web.config file

tom

hello all,

i have a web application that i want users to be able to
change the name of the server and database from a web page.

i have got this to work using this...

code:-

Public Sub SetValue(ByVal key As String, ByVal value
As Object)
Dim ds As New DataSet()
ds.ReadXml(System.Web.HttpRuntime.AppDomainAppPath
& "web.config")
Dim dr() As DataRow = ds.Tables("add").Select
(String.Concat("key='", key, "'"))
dr(0).Item("value") = value
ds.WriteXml
(System.Web.HttpRuntime.AppDomainAppPath & "web.config")
ds.Clear()
End Sub

called by this:
code:-

Dim aw As New AppSettinsWriter()
aw.SetValue("ConnectionPCSRead", "data source=" &
txtServer.Text & ";initial catalog=" & lblDatabase.Text
& ";persist security info=False;user
id=sa;password=;packet size=4096")

but i need to display the server and database apon load of
the web page, so the user can see what they are editing!

at the mo it's just empty text boxes.

I need to display the "data source" in the server box,
and to display the "initial catalog" in the database box.

please could you help,

thanks,

Tom.
Nov 19 '05 #1
1 10603
Hi,

it is not recommendable to let users write straight to the web.config file,
because it will also restart the ASP.NET application every time. That means
losing cache every time and so on.

However Jason Gaylord has written couple of articles about the subject so
perhaps you got take a peek on that:
http://aspalliance.com/jgaylord/colu...ebconfig1.aspx
http://aspalliance.com/jgaylord/colu...ebconfig2.aspx

--
Teemu Keiski
MCP,Designer/Developer
Mansoft tietotekniikka Oy
http://www.mansoft.fi

ASP.NET Forums Moderator, www.asp.net
AspAlliance Columnist, www.aspalliance.com

Email:
jo****@aspalliance.com

"tom" <to********@ukautomation.com> kirjoitti viestissä
news:92****************************@phx.gbl...

hello all,

i have a web application that i want users to be able to
change the name of the server and database from a web page.

i have got this to work using this...

code:-

Public Sub SetValue(ByVal key As String, ByVal value
As Object)
Dim ds As New DataSet()
ds.ReadXml(System.Web.HttpRuntime.AppDomainAppPath
& "web.config")
Dim dr() As DataRow = ds.Tables("add").Select
(String.Concat("key='", key, "'"))
dr(0).Item("value") = value
ds.WriteXml
(System.Web.HttpRuntime.AppDomainAppPath & "web.config")
ds.Clear()
End Sub

called by this:
code:-

Dim aw As New AppSettinsWriter()
aw.SetValue("ConnectionPCSRead", "data source=" &
txtServer.Text & ";initial catalog=" & lblDatabase.Text
& ";persist security info=False;user
id=sa;password=;packet size=4096")

but i need to display the server and database apon load of
the web page, so the user can see what they are editing!

at the mo it's just empty text boxes.

I need to display the "data source" in the server box,
and to display the "initial catalog" in the database box.

please could you help,

thanks,

Tom.

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Marek | last post by:
Hi there, my WinForm application has to be installed in "no-touch-deployment" mode, so users can run it from the web. I need to read application's .config file but it does not work in ...
0
by: Joan Bos | last post by:
Hi, Is there somewhere on the Internet a description of what a .NET application config file should contain? For our application, I have to write passwords encrypted in a config file. The...
3
by: Mustaq | last post by:
Hi, How to read same config file from different application? I have 4 application in VB.NET, all are using different app.config files. NOW I need all to read only one config file, how can I do...
3
by: Danny | last post by:
Hello, I was wondering if anyone knew if it was possible to make changes to an application's App.config file at runtime and then be able to access those changes immediately. The following is...
1
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; ...
0
by: Shaun Ram | last post by:
Hi, I have this constraint. A help would be greatly appreciated. I have this Config file. <?xml version="1.0" encoding="utf-8" ?> <configuration> <configsections> <sectionGroup...
4
by: Carlos AZ | last post by:
I have the following XML file named (applicattion.exe.config): <?xml version="1.0" encoding="utf-8" ?> <configuration> <AppSettings> <add key = "PathBD" value = "c:\project\data\maco.mdb" />...
5
by: Stephen Costanzo | last post by:
Looking back in the group, I figured out how to read from the appSettings section of the configuration file. I have default values for the application in the unlikely event that the user deletes...
5
by: Sridhar | last post by:
Hi, I have created a project which contains classes to read the data from the database. This project has an App.Config file which contains the SqlConnection String. when this code is called from...
5
by: CSharp-Jay | last post by:
So I have been programming in C# on a personal level as of lately, and am curious about something. Lately I have been experimenting around with file create/write, etc. I can open and read the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.