Config Creator in C#
Submitted by donbermoy on Friday, July 25, 2014 - 11:15.
Today in C#, i will teach you how to create a program that has a config creator in C#.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Next, add two Textboxes named textbox1 that holds the property name and textbox2 for the property value. Insert two buttons named Button1 that adds property and Button2 for saving config.
3. In your code view, put the following code:
We need to import the System.IO namespace in order to access files within the computers filesystem for saving later on.
To hold all the current properties to write to the config file in the near future, we will create a String list within the global scope with this variable:
4. Put this code in your Button1_Click to ensure that the property and values are not empty.
If they are both not nothing, we want to add the values using a delimiter of a colon (:) to separate the name from the value, to the list.
5. Put this code in your Button2_Click for saving the config file. This will allow the user to set a save destination through a new SaveFileDialog browser box, then use a new StreamWriter to write each property held within our 'props' list variable/object to the new config file.
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware
- using System.IO;
- If (Not TextBox1.Text = Nothing And Not TextBox2.Text = Nothing) Then
- Else
- End If
- props.Add(TextBox1.Text + ":" + TextBox2.Text)
- if (props.Count() > 0)
- {
- {
- fo.MultiSelect = false;
- fo.RestoreDirectory = true;
- fo.ShowDialog();
- if (fo.FileName == null)
- {
- MessageBox.Show("That config name is not valid.");
- }
- else
- {
- {
- foreach (string prop in props)
- {
- sw.WriteLine(prop);
- }
- }
- }
- }
- }
Add new comment
- 51 views