I want to delete any page from a word document. Is there any way to do it?
I can only delete some lines from the page. Is there any way to count the no of lines from the page? Then I can delete the whole page.. Or if there any other way of deleting the page, please help me then. Below I am giving the code that I have done.. which can only delete some lines from a page.
In textbox1, I am taking the value of the page no, which I want to delete.
private void button1_Click(object sender, EventArgs e)
{
string filePath = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open text/word File";
fDialog.Filter = "Text Files|*.txt|Doc Files|*.docx";
fDialog.InitialDirectory = @"C:\";
if (fDialog.ShowDialog() == DialogResult.OK)
{
filePath = fDialog.FileName.ToString();
}
object missing = System.Reflection.Missing.Value;
object fileName = filePath;
object readOnly = false;
object isVisible = true;
Word._Application oWord;
Word._Document oDoc1, oDoc2;
oWord = new Word.Application();
oWord.Visible = true;
oDoc1 = oWord.Documents.Open(ref fileName, ref missing, ref readOnly,
ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref isVisible, ref missing,
ref missing, ref missing, ref missing);
int y = 0;
int.TryParse(textBox1.Text.ToString(), out y);
object gotoPage = Word.WdGoToItem.wdGoToPage;
object gotoNext = Word.WdGoToDirection.wdGoToNext;
object gotoCount = null;
object gotoName = y;
object unit = Word.WdUnits.wdLine;
object count = 1;
object extend = Word.WdMovementType.wdExtend;
oWord.Selection.GoTo(ref gotoPage, ref gotoNext, ref gotoCount, ref gotoName);
oWord.Selection.MoveDown(ref unit, ref count, ref extend);
oWord.Selection.TypeBackspace();
}