Solved

Listbox displaying entire textfile in each enumeration

Posted on 2008-10-23
3
296 Views
Last Modified: 2013-12-17
I am current making a ajax enabled asp.net 2.0 C# web page using Visual studio. net 2005 that monitors and displays status of various servers by pulling their names from a textfile then pinging them and displaying the results via a listbox.

Below is the code i am using, it enumerates though the textfile and pings correctly, but at each enumeration it displays the entire text of the textfile according to the info gained from that ping such as:

Server1 pings as online and it displays Servers1 through 13 as all online, Server 2 pings as down so it displays Server1 though 13 as down and so on. Any ideas on what is causing this or how to correct it? Thank you!


protected void Page_Load(object sender, EventArgs e)

    {

        string[] servers = File.ReadAllLines(Server.MapPath("TestFile.txt"));

        foreach (string svr in servers)

        {

            PingSvr(svr);

        }

    }
 

    public void PingSvr(string hostName)

    {

        string[] servers = File.ReadAllLines(Server.MapPath("TestFile.txt"));

        foreach (string svr in servers)

        {

            Ping pingSender = new Ping(); PingOptions options = new PingOptions();

            // Use the default Ttl value which is 128,
 

            // but change the fragmentation behavior. 

            options.DontFragment = true;
 

            // Create a buffer of 32 bytes of data to be transmitted. 

            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
 

            byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);

            int timeout = 120;

            

            PingReply reply = pingSender.Send(hostName, timeout, buffer, options);
 

            if (reply.Status == IPStatus.Success)

            {

                ListBox1.Items.Add(svr + " is Online");

            }
 

            else

            {

                ListBox1.Items.Add("svr + "is Down");

            }

            

        }
 

    }

}

Open in new window

0
Comment
Question by:Figle
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
iHadi earned 500 total points
ID: 22792282
Hi

Your code has mistakes. I think the following code would do the job:

    protected void Page_Load(object sender, EventArgs e)

    {

        string[] servers = File.ReadAllLines(Server.MapPath("TestFile.txt"));

        foreach (string svr in servers)

        {

            PingSvr(svr);

        }

    }

 

    public void PingSvr(string hostName)

    {

            Ping pingSender = new Ping(); PingOptions options = new PingOptions();

            // Use the default Ttl value which is 128,

 

            // but change the fragmentation behavior. 

            options.DontFragment = true;

 

            // Create a buffer of 32 bytes of data to be transmitted. 

            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

 

            byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);

            int timeout = 120;

            

            PingReply reply = pingSender.Send(hostName, timeout, buffer, options);

 

            if (reply.Status == IPStatus.Success)

            {

                ListBox1.Items.Add(hostName + " is Online");

            }

 

            else

            {

                ListBox1.Items.Add(hostName + " is Down");

            }

            

        }

Open in new window

0
 

Author Comment

by:Figle
ID: 22792671
aw thanks alot that fixed it! *cheers you on*
0
 

Author Closing Comment

by:Figle
ID: 31509468
Thanks alot for the help!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Syntax error 9 45
How to add <appSettings> to the webconfig file 2 21
Vb. Net application freezes 9 30
designing in object programming 12 42
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now