Hi Firuz,
I have created sample that full fill your requirement.
HTML
<div>
<asp:Button ID="btnImport" runat="server" Text="Import" OnClick="Import" />
<br />
<asp:GridView ID="gvQuestions" runat="server" AutoGenerateColumns="true" />
</div>
Code
protected void Import(object sender, EventArgs e)
{
Application word = new Application();
Document doc = new Document();
string filePath = Server.MapPath("~/Files/Test.doc");
object missing = System.Type.Missing;
object fileName = filePath;
doc = word.Documents.Open(ref fileName,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing);
String read = string.Empty;
List<string> data = new List<string>();
for (int i = 0; i < doc.Paragraphs.Count; i++)
{
string temp = doc.Paragraphs[i + 1].Range.Text.Trim();
if (temp != string.Empty)
data.Add(temp);
}
doc.Close(ref missing, ref missing, ref missing);
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[] {
new System.Data.DataColumn("Id",typeof(int)),
new System.Data.DataColumn("Question"),
new System.Data.DataColumn("Answer1"),
new System.Data.DataColumn("Answer2"),
new System.Data.DataColumn("Answer3"),
new System.Data.DataColumn("Answer4"),
new System.Data.DataColumn("CorrectAnswer")
});
int totalQuestionCount = 0;
int rowNo = 1;
System.Data.DataRow dr = dt.NewRow();
for (int i = 0; i < data.Count; i++)
{
if (!data[i].Contains("$"))
{
dr[0] = rowNo;
dr[1] = data[i].Replace("@", "").Trim();
rowNo++;
}
else
{
int optionCount = 2;
foreach (string option in data[i].Split(';'))
{
if (!string.IsNullOrEmpty(option))
{
if (option.Contains("$"))
{
dr[optionCount] = option.Replace("$", "").Trim();
}
else if (option.Contains("©"))
{
dr[optionCount] = option.Replace("©", "").Trim();
dr[6] = option.Split(')')[1].Trim();
}
optionCount++;
}
}
}
if ((i - 1) % 2 == 0 && i != 0)
{
dt.Rows.Add(dr);
totalQuestionCount++;
dr = dt.NewRow();
}
}
((_Application)word).Quit();
gvQuestions.DataSource = dt;
gvQuestions.DataBind();
}
Screenshot