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

  • Home
  • SEARCH
  • 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 7833605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:47:31+00:00 2026-06-02T12:47:31+00:00

Ok I am going to try this again. I got more information now. I

  • 0

Ok I am going to try this again. I got more information now. I understand I can not use open and save dialogs and there is no database. So I am still kinda lost cause I was shown how to do it with open and save dialogs before. I am going to put what I am suppose to do and then so far the code I have. The code I have I have to build off and add too. I will also show what I am suppose to add to it. I am just trying to find the best way to understand this cause right now I am not. I am still new and I know the last couple days people have been trying to help me understand and then I was told it wasnt with the open and save dialog. Here is what I am suppose to do.

•Add a textbox named txtFilePath <— already have that

•Add a button next to the above textbox that says “Load” (name it appropriately)<-already have that

•Add a button that says “Save” (name it appropriately) <– already have this

•When thebutton “Load” is clicked, read the file specified in the textbox
(txtFilePath: Absolute path not relative) and add the objects found
within to the listbox<— Not understanding

•When the user clicks the “Save” button, write the selected record to
the file specified in txtFilePath (absolute path not relative) without
truncating the values currently inside<– not understanding

Here is the one part of code I have:`

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            EditDialog newEmployeeDialog = new EditDialog();
            if (newEmployeeDialog.ShowDialog() == DialogResult.OK)
            {
                employeeList.Items.Add(newEmployeeDialog.StaffMember);
            }
        }

        private void deleteButton_Click(object sender, EventArgs e)
        {
            if (employeeList.SelectedIndex == -1)
                return;

            if (MessageBox.Show("Really delete this employee",
                "Delete", MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question)
            == DialogResult.Yes)
            {
                employeeList.Items.Remove(
                    employeeList.SelectedItem);
            }
        }

        private void editButton_Click(object sender, EventArgs e)
        {
            if (employeeList.SelectedIndex == -1)
                return;

            int employeeNum = employeeList.SelectedIndex;
            EditDialog newEmployeeDialog = new EditDialog();
            newEmployeeDialog.StaffMember =
                (Employee)employeeList.SelectedItem;

            if (newEmployeeDialog.ShowDialog() == DialogResult.OK)
            {
                employeeList.Items.RemoveAt(employeeNum);
                employeeList.Items.Insert(employeeNum, newEmployeeDialog.StaffMember);
                employeeList.SelectedIndex = employeeNum;
            }
        }

        private void employeeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (employeeList.SelectedIndex != -1)
            {
                Employee currentEmployee = (Employee)employeeList.SelectedItem;
                firstName.Text = currentEmployee.FirstName;
                lastName.Text = currentEmployee.LastName;
                jobTitle.Text = currentEmployee.JobTitle;
            }
            else
            {
                firstName.Text = lastName.Text = jobTitle.Text = "";
            }
        }
`

Now I know you can not see the button click but I do have them mark. I know when you use open and save how it works. How I can go about this? I would use stream writer right.I understand that the user will type the path into the textbox and when the user hits load, it will load the file that they are specified. Now I am just trying to understand a code to be able to word this right.

would it be something like this:

String filePath = this.txtFilePath.Text;

since I need to name the textbox txtFilePath. I know some of you might say this is simple but when you are first learning it don’t seem that simple. I have been trying something to help me understand since I do my college from home. Thank you for reading hoping to hear from you guys.

Update: Would it be something like this

Reading a file

private void Load_Click(object sender, EventArgs e)
{ 
StreamReader myReader = new StreamReader(C:\\")
txtFilePath.Text = my reader.read to end();
myReader.Close();
}

then there is writing a file

{
StreamWriter myWriter = new StreamWriter("C:\\test.txt", true);
            myWriter.Write("Some text");
            myWriter.WriteLine("Write a line");
            myWriter.WriteLine("Line 2");
            myWriter.Close();
}

If this is correct then I have to get it where if the file is not there for the notepad to pop up so they can add it then they can save it without deleting anything out the file or files.

  • 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-06-02T12:47:36+00:00Added an answer on June 2, 2026 at 12:47 pm

    Assuming the file contains a list of employee names, you should be able to load them into your listbox using something like this:

    var filepath = txtFilePath.Text;
    if (File.Exists(filepath))
    {
        var lines = File.ReadAllLines(filepath);
        foreach (var line in lines)
            employeeList.Items.Add(line);
    }
    

    Then assuming you want to add a new employee name to the file that the user just entered into the listbox:

    var filepath = txtFilePath.Text;
    if (File.Exists(filepath))
        using (var sw = File.AppendText(filepath)) 
            sw.WriteLine((string)employeeList.Text);
    else
        using (var sw = File.CreateText(filepath)) 
            sw.WriteLine((string)employeeList.Text);    
    

    This hasn’t been tested, but it should work nearly as-is…

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

Sidebar

Related Questions

I'm going to try to explain this best I can I will provide more
I'm going to try and explain this as simply as I can, it's most
Ok, I'm going to try to make this more clear because my last question
When I try to check the do not show this screen again box and
Let me try this again, I'm going to leave out the exact data/example and
I am going to try to use left outer join between Ticket and Membership.
OK, I'm going to try my best to explain my problem. I have this
I'm going to try to explain this in simple terms, because it's probably shorter
I have got this super weird bug in my current project. To understand what
I've got a very simple question about a game I created (this is not

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.