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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:59:45+00:00 2026-05-13T06:59:45+00:00

I am new to programming. Is there a way to create multiple .txt files

  • 0

I am new to programming. Is there a way to create multiple .txt files using
data from another file in C#.
like this:
1. we have data.txt with 100 or more strings
string1
string2
string3

…
2. we have textbox1 and textbox2 waiting for user to enter strings

3 . we need to create 100 or more files using strings from data.txt and textboxes strings: name of the fisrt file : string1+textbox1string.txt
and inside it we write:
textbox2string + string1 + textbox1string
the same pattern to create other files, second – string2+textbox1string.txt and inside second – textbox2string + string2 + textbox1string
sorry for my english i am not native speaker.

  • 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-13T06:59:46+00:00Added an answer on May 13, 2026 at 6:59 am

    Well, it sounds like you want something like:

    string[] lines = File.ReadAllLines("file1.txt");
    foreach (string line in lines)
    {
        File.WriteAllText(line + textbox1.Text + ".txt",
                          textbox2.Text + line + textbox1.Text);
    }
    

    Basically for very simple tasks like this, the methods in the File class allow “one shot” calls which read or write whole files at a time. For more complicated things you generally have to open a TextReader/TextWriter or a Stream.

    If this wasn’t what you were after, please provide more information. Likewise if you find the code hard to understand, let us know and we’ll try to explain. You may fine it easier with more variables:

    string[] lines = File.ReadAllLines("file1.txt");
    foreach (string line in lines)
    {
        string newFile = line + textbox1.Text + ".txt";
        string fileContent = textbox2.Text + line + textbox1.Text;
        File.WriteAllText(newFile, fileContent);
    }
    

    EDIT: If you want to add a directory, you should use Path.Combine:

    string newFile = Path.Combine(directory, line + textbox1.Text + ".txt");
    

    (You can do it just with string concatenation, but Path.Combine is a better idea.)

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

Sidebar

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.