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.
Well, it sounds like you want something like:
Basically for very simple tasks like this, the methods in the
Fileclass allow “one shot” calls which read or write whole files at a time. For more complicated things you generally have to open aTextReader/TextWriteror aStream.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:
EDIT: If you want to add a directory, you should use
Path.Combine:(You can do it just with string concatenation, but
Path.Combineis a better idea.)