Follow by Email

Wednesday, 10 April 2013

How to add XML Config or use XML file data in our Class in C# .Net

Firstly, add an XML file from add new item :

<?xml version="1.0" encoding="utf-8" ?>

<Config>
  <Settings>
    <Hosturl>https://identity.api.rackspacecloud.com/v1.0</Hosturl>
    <Username>rbarrueco</Username>
    <Userkey>3a8949c3aded132ba97e7ec88b4ab7bc</Userkey>
  </Settings>
</Config>

Then in your Class or Code behind :

DataSet objDs = new DataSet();
 objDs.ReadXml(@"E:\Config.xml");
                foreach (DataRow dr in objDs.Tables["Settings"].Rows)
                {

                    Hosturl = dr["Hosturl"].ToString();
                    Username = dr["Username"].ToString();
                    Userkey = dr["Userkey"].ToString();


                }


0 comments:

Post a Comment


                                                            

 
Design by Abhinav Ranjan Sinha