Hi,
Below are code... Please rectify my problem....
private void button1_Click(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines("D:\\blogspot.txt");
int partitionSize = 2;
int partitionNumber = (lines.Length - 1) / partitionSize;
int partitionRemainder = (lines.Length - 1) % partitionSize;
string[] partitionLines = new string[partitionSize + 1];
partitionLines[0] = lines[0]; // copy heading
int part;
for(part = 1; part <= partitionNumber; part++)
{
int startIndex = (part - 1) * partitionSize + 1;
Array.Copy(lines, startIndex, partitionLines, 1, partitionSize);
string fileName = "gopi" + part.ToString() + ".txt";
using (StreamReader sr = File.OpenText(fileName ) )
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
File.WriteAllLines(s.ToString ());
}
}
}
if (partitionRemainder > 0)
{
int startIndex = (part - 1) * partitionSize + 1;
partitionLines = new string[partitionRemainder + 1];
partitionLines[0] = lines[0];
Array.Copy(lines, startIndex, partitionLines, 1, partitionRemainder);
string fileName = "gopi" + part.ToString() + ".txt";
//File.WriteAllLines(fileName, partitionLines);
FileStream fs = null;
if (!File.Exists(fileName ))
{
using (fs = File.Create(fileName.ToString() ))
{
File.WriteAllLines(fileName, partitionLines);
}
}
}
}
Agopi.Net, if this helps please login to Mark As Answer. | Alert Moderator