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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:38:48+00:00 2026-05-21T08:38:48+00:00

I am trying to created a csv file where each entry is inputed by

  • 0

I am trying to created a csv file where each entry is inputed by the user. Once one set of of values have been entered it should move on to the next. However I cannot seem to do the bit. Each time i run the program, it replaces the previous values.

using System;
using System.IO;
using System.Collections.Generic;


namespace FileAccess
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string FName;
            string LName;
            string Dpt;
            string Grade;
            string NumberOfHours;

            string file_name = "EmployeeDetails.txt";

            System.IO.StreamWriter objWriter;
            objWriter = new System.IO.StreamWriter(file_name);

            String[] ArrayDetails = new string[5];

            Console.Write("Enter Emp First Name: ");
            FName=Console.ReadLine();
            Console.Write("Enter Emp Last Name: ");
            LName = Console.ReadLine();
            Console.Write("Enter Emp Department: ");
            Dpt = Console.ReadLine();
            Console.Write("Enter Employee Grade: ");
            Grade = Console.ReadLine();
            Console.Write("Enter Number Of Hours Worked: ");
            NumberOfHours = Console.ReadLine();

            ArrayDetails[0] = FName;
            ArrayDetails[1] = LName;
            ArrayDetails[2] = Dpt;
            ArrayDetails[3] = Grade;
            ArrayDetails[4] = NumberOfHours;

            // Create new list of strings
            List<string> LDetails = new List<string>(); // Create new list of strings
            LDetails.Add(FName); // Add string 1
            LDetails.Add(LName); // 2
            LDetails.Add(Dpt); // 3
            LDetails.Add(Grade); // 4
            LDetails.Add(NumberOfHours); // 5
            //OutPut the data into the file
            string LDetailsCSV = string.Join(",", LDetails.ToArray());
            Console.WriteLine(LDetailsCSV);
            objWriter.Write(LDetailsCSV);
            objWriter.Close();
        }
    }
}

Some advise please.

  • 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-21T08:38:48+00:00Added an answer on May 21, 2026 at 8:38 am

    The StreamWriter constructor will overwrite the file you are using if it exists. There is an overloaded constructor to which you can pass a boolean as a second argument to tell it to append:

    System.IO.StreamWriter objWriter;
    objWriter = new System.IO.StreamWriter(file_name, true);
    

    In addition, the Write method you are using will not append a line break. If you use the WriteLine method, it will.

     Console.WriteLine(LDetailsCSV);
     objWriter.WriteLine(LDetailsCSV);
     objWriter.Close();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a csv file of some data. I have wrote
I have a time series(a csv file) data that looks like below. Each observation
I am trying to create a CSV file from a dynamically generated table.I have
I have created a simple form which is loading a csv file with few
I have a stored procedure called sp_BulkInsert that inserts one .csv file into my
I have 7 csv files and one xls file. In the xls file I
I'm trying to create a simple Silverlight application that involves parsing a CSV file
I have created a datatable and trying to insert that datatable through SqlBulkCopy but
I am trying to import data into rails (3.1) and I have created this
I am trying to parse a csv file where my data is given in

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.