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 7839359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:25:29+00:00 2026-06-02T15:25:29+00:00

I am working on this project still and I am running into a problem.

  • 0

I am working on this project still and I am running into a problem. Well here is what I need to do.

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 and handle any exceptions that arise.

Ok here is my code:

 private void Save_Click(object sender, EventArgs e)
    {

        string filePath = txtFilePath.Text;

        if (!File.Exists(filePath))
        {
            FileStream fs = File.Create(filePath);
            fs.Close();
        }

        using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write))
        {
            using (StreamWriter sw = new StreamWriter(fs))
            {
                foreach (string line in employeeList.Items)
                {
                    sw.WriteLine(line);
                }
            }
        }
            }

Now when I go onto my program and want to save something from the employeelist.text that its not being saved to the place I am saving it at. I don;t know if I am missing something in my code or what but it will not save. Here is an example:

I add a person name to this list in employeelist and in the textbox I
have a file called C:\employess\employeelist.txt I want to save it to.
I click the save button then I go to that employeelist and it is not
being saved.

I don’t know what I am doing wrong I have been looking online for a solution but I haven’t found anything yet. Thanks

  • 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-02T15:25:30+00:00Added an answer on June 2, 2026 at 3:25 pm

    Some things to double-check:

    • Make sure you don’t have the employeelist.txt file open when you’re testing
    • Make sure you don’t have invalid characters in your file name
    • Make sure your application has permission to save the file to the location you specified
    • Use the debugger to step-through your code and look for swallowed exceptions — there must be a reason the file is not created.
    • Check that your Save_Click event is wired up to your button — is the code in your example even running?

    Once you check those things, you may want to follow this example for the create vs. append requirement of your project:

    string path = txtFilePath.Text;
    
    // This text is added only once to the file.
    if (!File.Exists(path)) 
    {
        using (StreamWriter sw = File.CreateText(path)) 
        {
            foreach (var line in employeeList.Items)
                sw.WriteLine(line.ToString());
        }   
    } 
    else 
    {
        using (StreamWriter sw = File.AppendText(path)) 
        {
            foreach (var line in employeeList.Items)
                sw.WriteLine(line.ToString());
        }
    }
    

    This will create the file if it doesn’t exist, or append to it if it does.

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

Sidebar

Related Questions

I am working on this project where I need to read in a lot
I'm running into a problem with a user not being able to push his
I'm working on this project where the client has a virtual server setup. I
I'm working on this project and the customer wants it to integrate with a
I'm working on this project and I have to open a new browser tab.
I've been working on this project for about two weeks now. I don't understand
So I have been working on this project for a short while now. I
On this project I am working on right now, one of the newest feature
I am working on a small project for learning PHP better. This project has
I'm working on a project in C#, it's about E-learning.This project should use plug-ins

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.