Click here to Skip to main content
15,905,971 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi,

I want to update the below config file and i am saving this file as ACE.config file

XML
<?xml version="1.0" encoding="utf-8"?>
<ACE xmlns="urn:www.ace.com/services/sol/report/2.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Level> report </Level>
  <Output>abc  </Output>
  <Name>  </Name>
  <Password encrypted="false" alg="2.0" pwd="PhassPhrase" required="Y">plain text</Password>
  <delete> Yes</delete>
</ACE>


Here the problem i am facing is, i am not able to update the password tag if file extension is .config file if it is .xml i am able to do. Please help me out to update the password attributes and innertext of the Password Element.
<Password encrypted="false" alg="2.0" pwd="PhassPhrase" required="Y">plain text</Password>

if required value is Y then i need to update the encrypted ="True" adn pwd="pwd is encrypted" and PlainText (InnerText) to XYZ.

Note : Extension of the file should be .config

I am writting below code : to update the Password. But it's not all going into for loop
Note : Extension of the file should be .config

C#
XDocument xmlFile = XDocument.Load(@"D:\ACE\ConfigFiles\ACE.config");

                    var query = from c in xmlFile.Elements("ACE").Elements("Password")
                                select c;

                    foreach (XElement password in query)
                    {

 if(password.Attribute("required").Value=="y")
                    {
                        password.Attribute("encrypted").Value = "true";
                        password.Attribute("salt").Value = "PhassPhrase";
                        password.Value = "EncryptedText";
                        }
                    }
                    // save the XmlDocument back to disk
                    xmlFile.Save(@"D:\ACE\ConfigFiles\ACE.config");


Thanks in Advacnce,
Subhash G.
Posted
Updated 9-Feb-13 19:52pm
v3
Comments
Sergey Alexandrovich Kryukov 9-Feb-13 0:53am    
There is no such thing as "extension". And this is XML.
—SA
subash.g13 9-Feb-13 1:51am    
I update the code snippet, could you please look and let me know what's wrong in that.

1 solution

Hi Subash,
In your shown code there seems to be nothing that will behave differently if you change the XML file extension. The extension has no meaning in that context.

Suggestion: try other extensions, other locations, other names, and see what you get...

Cheers,
Edo
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900