Hello,
I have a web application that browses the local system, selects a file and uploads it onto the webpage. The entire contents of the selected document is displayed in the textarea on the webpage itself. The uploaded file is of .docx type. The selected word file has many paragraphs with different headings. I want my program to select a particular section in the word document by specifying the heading and display only that section in the text area. Could you please help me in doing this?
Thanks in advance,
Vinutha
using System;
using System.IO;
using Microsoft.Office.Interop.Word;
using System.Text;
using System.Collections.Generic;
using System.Windows.Forms;
namespace ReqDigester
{
public partial class _Default : System.Web.UI.Page
{
private object path;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void Button3_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application Objword = new Microsoft.Office.Interop.Word.Application();
Document objdoc = new Document();
dynamic FilePath = Path.GetFullPath(FileUpload1.PostedFile.FileName);
dynamic NA = System.Type.Missing;
objdoc = Objword.Documents.Open
(ref FilePath, ref NA
);
StringBuilder sb = new StringBuilder();
for (int Line = 0; Line < objdoc.Paragraphs.Count; Line++)
{
string Filedata = objdoc.Paragraphs[Line + 1].Range.Text.Trim();
if (Filedata != string.Empty)
{
sb.AppendLine(Filedata);
}
}
((_Document)objdoc).Close();
((_Application)Objword).Quit();
TextBox2.Text = Convert.ToString(sb);
}
}
}