Thanks
Murugavels
Murugavels
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit Kumar SinghRank #562 · 4.3K reputationPosted Mar 15, 2016, 11:16 PM EDT
Murugavel S69 reputationPosted Mar 16, 2016, 12:37 AM EDT
thnks for ur reply..
but i need is have to create multiple files..
const string sourceFileName = @"\Test.txt";
const string destinationFileName = @"\Test{0}.txt";
const int linesPerFile = 50;
using (var sourceFile = new StreamReader(sourceFileName))
{
var fileCounter = 0;
var destinationFile = new StreamWriter(
string.Format(destinationFileName, fileCounter + 1));
try
{
var lineCounter = 0;
string line;
while ((line = sourceFile.ReadLine()) != null)
{
// Did we reach the maximum number of lines for the file?
if (lineCounter >= linesPerFile)
{
// Yep... Time to close this one and
// switch to another file
lineCounter = 0;
fileCounter++;
destinationFile.Dispose();
destinationFile = new StreamWriter(
string.Format(destinationFileName, fileCounter + 1));
}
destinationFile.WriteLine(line);
lineCounter++;
}
}
finally
{
destinationFile.Dispose();
}
}
but i want to use linq to achieve this..
can u help me..