.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Post New Resource Bookmark and Share   

Read XML files in C#

Posted By:kamlesh       Posted Date: July 26, 2011    Points: 200    Category:    URL: http://www.dotnetspark.com  

How to read XML file in C#
 

ReadXMLFile(System.AppDomain.CurrentDomain.BaseDirectory + "\\SEM_MailboxList.xml", treeViewBricklevelBackupMailbox.TopNode);


   public void ReadXMLFile(String strFilePath, TreeNode otree)
        {
            //strFilePath = "C:\\SEM_MailboxList.xml";
            try
            {

                XmlDocument objXMLDocument = new XmlDocument();
                objXMLDocument.Load(strFilePath);

                XmlNode xmlNodeValue = objXMLDocument.SelectSingleNode("/Server/ServerName");
                string strServer = xmlNodeValue.InnerText;

                TreeNode top = treeViewBricklevelBackupMailbox.Nodes.Add(strServer);



                xmlNodeValue = objXMLDocument.SelectSingleNode("/Server/StorageGroupCount");
                int iUserCounter = Int32.Parse(xmlNodeValue.InnerText);


                for (int iCounter1 = 1; iCounter1 <= iUserCounter; iCounter1++)
                {
                    String strPathofUserMetaData = "/Server/StorageGroup" + "[" + iCounter1 + "]";
                    XmlNode xmlNodeValueName = objXMLDocument.SelectSingleNode(strPathofUserMetaData + "/Name");
                    string StrName = xmlNodeValueName.InnerText;
                    TreeNode sg = top.Nodes.Add(StrName);

                    XmlNode xmlNodeMB = objXMLDocument.SelectSingleNode(strPathofUserMetaData + "/Mailbox");
                    string StrMailBox = xmlNodeMB.InnerText;
                    string[] strUsers = StrMailBox.Split(';');
                    for (int iMB = 0; iMB < strUsers.Length - 1; iMB++)
                    {
                        int iSM = strUsers[iMB].IndexOf("SystemMailbox");
                        int iSA = strUsers[iMB].IndexOf("System Attendant");
                        if (iSM == -1 && iSA == -1)
                            sg.Nodes.Add(strUsers[iMB]);
                    }
                }
                top.Expand();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
        }



 
-
  SP-SWD-T01
  2
-
  FirstStorageGroup
  SystemMailbox
 

-
  TestSG
  Birbal;akbar;Raja;SystemMailbox{47BA2877-62C5-4EE8-9649-46757545762D};
 

 

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend