A bit of background:
I am currently working on an application that allows novice computer users to test their ping without having to go into the command prompt.
My application works, but I would very much like to take the application to the next level and feed in default form values from a locally stored .INI file.
I can give people the existing code, but I stress that this application works – I am just interested in advancing the code so I can read in default form values.
using System;
using System.Collections.Generic;
using System.Net;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace Ping_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void pingButton_Click(object sender, EventArgs e)
{
if (pingAddressTextBox.Text != "")
{
DataTable resultsList = new DataTable();
resultsList.Columns.Add("Time", typeof(int));
resultsList.Columns.Add("Status", typeof(string));
for (int indexVariable = 1; indexVariable <= timesToPing.Value; indexVariable++)
{
string stat = "";
Ping pinger = new Ping();
PingReply reply = pinger.Send(pingAddressTextBox.Text);
if (reply.Status.ToString() != "Success")
stat = "Failed";
else
stat = reply.RoundtripTime.ToString();
pinger.Dispose();
resultsList.Rows.Add(Convert.ToInt32(reply.RoundtripTime), reply.Status.ToString());
}
resultsGrid.DataSource = resultsList;
minPing.Text = resultsList.Compute("MIN(time)", "").ToString();
maxPing.Text = resultsList.Compute("MAX(time)", "").ToString();
avgPing.Text = resultsList.Compute("AVG(time)", "").ToString();
}
else
{
MessageBox.Show("You are required to enter an address.");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
I am uncertain how to go about it? Where would the default.ini file be stored for my application?
Also any comments on the existing code are welcomed.
If anyone can help I would be grateful.
Many Thanks,
J
You can store your default values in ini file (i.e config file), this default file will be stored in your system D or C folder…
and from that file you can get those default values from the ini file by the following method
make a class like this INifile.cs and place the below code in ini.cs
and the values in config file look like this ….
you can get this values like by using
you will get the value like this 1234
pls let me know if this is unclear to understand
i hope it will helps you……