Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6713557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:23:41+00:00 2026-05-26T08:23:41+00:00

A bit of background: I am currently working on an application that allows novice

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:23:41+00:00Added an answer on May 26, 2026 at 8:23 am

    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

     /// <summary>
    /// This will read config.ini file and return the specific value
    /// </summary>
    /// <param name="MainSection">Main catergory name</param>
    /// <param name="key">name of the key in main catergory</param>
    /// <param name="defaultValue">if key is not in the section, then default value</param>
    /// <returns></returns>
    public static string getIniValue(string MainSection, string key, string defaultValue)
    {
      IniFile inif = new IniFile(AppDataPath() + @"\config.ini");
      string value = "";
    
      value = (inif.IniReadValue(MainSection, key, defaultValue));
      return value;
    }
    
    public static string AppDataPath()
    {
      gCommonAppDataPath = @"c:\" + gCompanyName + @"\" + gProductName; // your config file location path
      return gCommonAppDataPath;
    }
    

    make a class like this INifile.cs and place the below code in ini.cs

     public class IniFile
     {
        public string path;
    
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);
    
        /// <summary>
        /// INIFile Constructor.
        /// </summary>
        /// <param name="INIPath"></param>
        public IniFile(string INIPath)
        {
            path = INIPath;
        }
        /// <summary>
        /// Write Data to the INI File
        /// </summary>
        /// <param name="Section"></param>
        /// Section name
        /// <param name="Key"></param>
        /// Key Name
        /// <param name="Value"></param>
        /// Value Name
        public void IniWriteValue(string Section,string Key,string Value)
        {
            WritePrivateProfileString(Section,Key,Value,this.path);
        }
    
        /// <summary>
        /// Read Data Value From the Ini File
        /// </summary>
        /// <param name="Section"></param>
        /// <param name="Key"></param>
        /// <param name="Path"></param>
        /// <returns></returns>
        public string IniReadValue(string Section,string Key,string Default)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section,Key,Default,temp,255,this.path);
            return temp.ToString();
    
        }
        public void IniWriteString(string Section, string Key, string Value)
        {
            WritePrivateProfileString(Section, Key, Value, this.path);
        }
        public string IniReadString(string Section, string Key, string Default)
        {
            StringBuilder temp = new StringBuilder(255);
            int i = GetPrivateProfileString(Section, Key, Default, temp, 255, this.path);
            return temp.ToString();
        }
     }
    

    and the values in config file look like this ….

      [System]
      GroupCode=xx
      SiteCode=1234
      MemberPrefix=xxx
      AutoStart=no
      EnablePosButton=yes....
    

    you can get this values like by using

    string a = getIniValue("System", "Sitecode", "");
    

    you will get the value like this 1234

    pls let me know if this is unclear to understand

    i hope it will helps you……

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing an application that allows one to store images, and then tag
A little background I'm working on an .net application that's uses plugins heavily, the
For a bit of background, I'm writing a meter reading application in C for
Background I'm having a bit of trouble finding out just how to programmatically post
This feature worked a bit, then stopped working. Background: Given a user is logged
Background: I find myself harnessing F# Records a lot. Currently I am working on
Just a bit of background first. I currently have a site hosted with Windows
I am currently working on an Android app and I am having some issues
First a bit of background. I have been working on the MS platform for
I am currently working on a website, whose URL is http://lathamcity.com/ The problem that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.