Dinesh Kumar
asked on
Going to New Page in Ms Word using C#
Hi,
I am working on creating Word File from Text File having some matter:
I want to go to new page on certain condition in Ms Word. How can I do it?
I am using the following class to create Dataset from a text File.
and then calling as follows:
Please see the else part of the below code where i am trying to go to the new Page in the same file.
I am working on creating Word File from Text File having some matter:
I want to go to new page on certain condition in Ms Word. How can I do it?
I am using the following class to create Dataset from a text File.
public class TextToDataset
{
public static DataSet Convert(string File,string TableName, string delimiter)
{
DataSet result = new DataSet();
StreamReader s = new StreamReader(File);
result.Tables.Add(TableName);
string AllData = s.ReadToEnd();
string[] rows = AllData.Split("\r\n".ToCharArray());
result.Tables[TableName].Columns.Add("DATA");
foreach (string r in rows)
{
string[] items = r.Split(delimiter.ToCharArray());
result.Tables[TableName].Rows.Add(items);
}
return result;
}
}
and then calling as follows:
Please see the else part of the below code where i am trying to go to the new Page in the same file.
DataSet ds = TextToDataset.Convert(file, "MyNewTable", "\t");
#region For Each Loop through data set
//For loop through data set
foreach (DataRow dr in ds.Tables[0].Rows)
{
for (int i = 0; i < ds.Tables[0].Columns.Count; i++)
{
if (dr[i].ToString() != "")
{
string[] bits = dr[0].ToString().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//if clean getting the value N
string IsClean = bits[1].ToString();
//checking whether the record is clean or not
if (IsClean == "N")
{
//writting clean record to the file
using (var fileWriter = File.AppendText(filefinal))
{
string[] clean = dr[i].ToString().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string licence = clean[0].ToString();
string character = clean[1].ToString();
string finallicence = clean[2].ToString();
fileWriter.WriteLine(clean[0].ToString() + " "+ clean[1].ToString() +" "+"Clean Record");
fileWriter.WriteLine(clean[2].ToString());
fileWriter.WriteLine(System.Environment.NewLine);
}
}
else
{
[b] //want to write here on the New Page but it does not go the new page Please Help!)[/b]
using (var fileWriter = File.AppendText(filefinal))
{
fileWriter.WriteLine(dr[i].ToString());
fileWriter.WriteLine(System.Environment.NewLine);
}
}
}
}
}
}
#endregion
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
fileWriter.WriteLine("\f") ;
Worked!
Thank You.
Worked!
Thank You.
ASKER
To the Point Solution!
ASKER