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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:36:21+00:00 2026-06-17T09:36:21+00:00

After following this topic I am able to create the new row but my

  • 0

After following this topic I am able to create
the new row but my question is how do
I save or write the new line to the file?

I tried ‘StreamWriter’ but it only writes the newly
created line.

Any suggestions please?

Here is my code so far:

string path = @"C:/CSV.txt";

string[] lines = File.ReadAllLines(path);

var splitlines = lines.Select(l => l.Split(','));

foreach (var line in splitlines)
{
   if(line[1].Contains("34"))
   {                                        
     line[1] = "100";
     var newline = string.Join(",", line);
     StreamWriter sr = new StreamWriter(path);    
     sr.WriteLine(newline);
     sr.Close();                                      
   }
 }
  • 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-17T09:36:22+00:00Added an answer on June 17, 2026 at 9:36 am

    Here is your solution using StreamReader class:

    String path = @"C:\CSV.txt";
    List<String> lines = new List<String>();
    
    if (File.Exists(path));
    {
        using (StreamReader reader = new StreamReader(path))
        {
            String line;
    
            while ((line = reader.ReadLine()) != null)
            {
                if (line.Contains(","))
                {
                    String[] split = line.Split(',');
    
                    if (split[1].Contains("34"))
                    {
                        split[1] = "100";
                        line = String.Join(",", split);
                    }
                }
    
                lines.Add(line);
            }
        }
    
        using (StreamWriter writer = new StreamWriter(path, false))
        {
            foreach (String line in lines)
                writer.WriteLine(line);
        }
    }
    

    If you want to overwrite the file, use this StreamWriter constructor with append = false.

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

Sidebar

Related Questions

I asked this question earlier, and after thinking about the topic some more, I
I'm still slightly confused after reading this topic. Is the following C++ expression *d++
After following this MVC 4 tutorial series I was trying some of the stuff
After following the steps outline in this Fluent NHibernate tutorial I am stuck on
After hours I am giving up on debugging the following: This works: URL[] urls
After resolving issues with RIA installation here , I'm still getting this following error.
following up with this topic: (Rails) How to display child records (one-to-many) in their
This is just a general question for my information. I know how to create
I previously asked a similar question on this topic a while back and got
After referencing many previous questions and answers on this topic, I am still stumped.

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.