3

I have a XML file which contains the following:

<config>
  <webservices>
     <webservice>
       <name>A</name>
       <value>http://www.123.com</value>
     </webservice>
     <proxy enabled="false" useiedefault="false">
       <name>
       </name>
       <value>
       </value>
     </proxy>
  </webservices>
</config>

Is there a way to change the values of 'webservice value' (from the XML file) through textbox in C# and save/update it afterwards?

TextBox1.Text = "http://www.abc.com";
// change value of xml
1
  • are you allowed to use javascript? if so then try using javascript Commented Jul 23, 2010 at 9:22

2 Answers 2

3

I was getting a "File already opened by something else" type error.

This is your code that I modified and now it works for me:

StreamReader fileStream = new StreamReader(filename);

var doc = new XmlDocument();

doc.Load(fileStream);

var node = doc.SelectSingleNode(@"config/webservices/webservice/value");

node.InnerText = TextBox1.Text;

fileStream.Close();

doc.Save(fileName);

Sign up to request clarification or add additional context in comments.

Comments

1

This code fragment should work, where fileName is the full path to your XML file:

var doc = new XmlDocument();
doc.Load(fileName);
var node = doc.SelectSingleNode(@"config/webservices/webservice/value");
node.InnerText = TextBox1.Text;
doc.Save(fileName);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.