Hi guys...

I'm trying to put in a IF statement that checks to see if there is any STMP Value within the XML file. Code is below...

Code:

       private void Send_Click(object sender, EventArgs e)
        {
            if (File.Exists(@"C:\Timewade\Quickticket\Person.xml"))
            {
                XmlNodeList detailsCheck = smtpDetails.GetElementsByTagName("SMTP_Server");

                if (detailsCheck[0].InnerText == null)
                {
                    MessageBox.Show("Please Fill in SMTP Details");
                }

                smtpDetails = new XmlDocument();
                smtpDetails.Load(PATH);

Stepping-through the code it does hit the first part of the "IF" Statement but after that ignores the 'MessageBox' and continues through to an exception.

The XML I believe is blank, Below is Blank XML generated by C#.

Code:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<Table> -<SMTP_details> <SMTP_Server/> <SMTP_Port/> <SMTP_Username/> <SMTP_Password/> <Company_Name/> <Company_Tel/> </SMTP_details> </Table>

am i trying to check the wrong section???

Unrelated to the current question, why do your auto generated XML files always have a - before <table>? It technically invalidates the XML file structure :) will probably a rogue - in your XML construction code

Change your if statement to check for string.Empty instead of null :) Should solve the issue as it currently reads the .InnerText as "" which is the equiv of string.Empty.

Changes to your XML to make it generate valid files:
- Get rid of the rogue -
- Change standalone="true"?> to standalone="yes"?> as it only accepts a yes/no response.

Hi Mikey,

I think its becasue I took some of the code from a tutorial and left it in there.. I have removed it now so that the xml that is built now looks like this...

Code:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<SMTP_details> <SMTP_Server/> <SMTP_Port/> <SMTP_Username/> <SMTP_Password/> <Company_Name/> <Company_Tel/> </SMTP_details>

however, still get the problem with the IF statement not seeing that the STMP_Server section is blank.

Susses it!..

as its a blank string an not a a NULL it should be ""

Again my console line version:

            string XMLFilePath = @"C:\Users\maskew\Documents\DaniWeb\TestXML.xml";

            XmlDocument XmlFile = new XmlDocument();
            XmlFile.Load(XMLFilePath);

            XmlNodeList Results = XmlFile.GetElementsByTagName("SMTP_Server");
            Console.WriteLine(Results[0].InnerText);

            if (Results[0].InnerText == string.Empty)
            {
                Console.WriteLine("Please Fill in SMTP Details");
            }

            SmtpClient client = new SmtpClient(Results[0].InnerText);
            Console.ReadLine();

My If statement triggers the writeline using your provided blank XML document.

Hmm I believe I have your XML generation code in my inbox? I will have a look at it when I get a minute.

Thanks for that Mikey, I've managed to resolve it and it works really well now!

I have 1 final issue which should be quite easy I hope.. I shall explain in a min..

OK... here goes. Thas last little niggle.

When a user opens the program it prompts for SMTP details to be completed. The user logs in, completes the SMTP details on the AdminControl.CS form and then that in turn updates the read XML.. all good.

However when closing the admin screen and returning to the main form it does not pull through the Company name and Telephone number. You have to restart the program to show this so I am guessing its a refresh issue.

I have seend in intellisense some refresh items but not to sure on the best way to use them.

The "Apply Changes" button on the AdminControl.cs is where the XML is created and then closes the form window. I am guessing I need a refresh control in here to refresh the main program window (form1.cs)

thanks for all your help as usual!

sorry for the delayed reply.

So from my understanding you need to refresh the main form on the close of the admin one?

Good morning Mikey,

That is correct.. I'm guessing I need to somehow re-load the xml file.

I did start a new thread with the code inside if you want to look at it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.