Link to home
Start Free TrialLog in
Avatar of Varshini S
Varshini S

asked on

How to read a string using InnerXml ?

I am using following code to read a string from XML file. I have to read
a following  string from the XML file. How to read this string ?  "mcQKhSSzcMP9199vA8Bod1/y6VJrZNL3m4AQiDHwonHyuSUctBQY/cgOz5rakHa2d5mVKSSxdE2RjDDB0DxKUsoWbddaeej6ufY6fUj6ACmwJQyiB+I3OA=="



c# code:
  XmlDataDocument doc = new XmlDataDocument();
            doc.Load(@"C:\Temp\Connection.exe.config");
           
            
            XmlElement root = doc.DocumentElement;
     XmlNodeList elemList = root.GetElementsByTagName("connectionStrings");

Open in new window




XML File:


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
      <clear/>
      <add name="Encrypted"
             providerName="System.Data.SqlClient"
             connectionString="mcQKhSSzcMP9199vA8Bod1/y6VJrZNL3m4AQiDHwonHyuSUctBQY/cgOz5rakHa2d5mVKSSxdE2RjDDB0DxKUsoWbddaeej6ufY6fUj6ACmwJQyiB+I3OA=="
		/>
    </connectionStrings>
    </configuration>

Open in new window

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <connectionStrings>
      <clear/>
      <add name="Encrypted"
             providerName="System.Data.SqlClient"
             connectionString="mcQKhSSzcMP9199vA8Bod1/y6VJrZNL3m4AQiDHwonHyuSUctBQY/cgOz5rakHa2d5mVKSSxdE2RjDDB0DxKUsoWbddaeej6ufY6fUj6ACmwJQyiB+I3OA=="
		/>
    </connectionStrings>
    </configuration>

Open in new window

Avatar of ste5an
ste5an
Flag of Germany image

Don't access your config files manually. Use the ConfigManager class instead.
Avatar of Varshini S
Varshini S

ASKER

ste5an: You are absolutely correct. But for this scenario  I need to read manually.
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You are alreading reading your string. But I guess you want to decrypt this string.

Normally you would use an Protected Configuration Provider.

The problem is quite simple: I don't recognize this encryption schema...

So hard to tell. How was this config file generated?
@ste5an - Offhand it looks like an encoded public or private key generated using the RSACryptoServiceProvider.

-saige-
ste5an - Application configuration file sitting in outside my application and more than 5 application sharing the same config file. So I have used TripleDES  encryption and generated the keys. During the run time I will decrypt the connection string.
@Varshini - Have you looked at the code I provided to see if that leads you down the right path?  If needed I could provide more information.

-saige-
Saige- Thank You. This works for me
Don't forget to accept the solution.

-saige-