Thanks to Zoltán Zörgő :), Done it !!!!!!.
Below is the code
using System;
using System.Collections.Generic;
using System.Collections;
using System.Diagnostics;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using System.IO;
namespace DocToHtm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string dir = @"C:\CONVERT\";
string dirTar = @"C:\CONVERT\DOC FILES\";
int take = Directory.GetFiles(dir, "*.doc", SearchOption.TopDirectoryOnly).Length;
MessageBox.Show(take.ToString());
string[] array = Directory.GetFiles(dir, "*.doc");
if (take > 0)
{
try
{
foreach (string name in array)
{
Word._Application newApp = new Word.Application();
string filename = Path.GetFileName(name);
MessageBox.Show(filename);
string filenoext = Path.GetFileNameWithoutExtension(name);
object Sourcepath = name.ToString();
if (Directory.Exists(dirTar))
{
object TargetPath = @"C:\CONVERT\" + filenoext;
object Unknown = Type.Missing;
Word.Documents d = newApp.Documents;
Word.Document od = d.Open(ref Sourcepath, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown);
object format = Word.WdSaveFormat.wdFormatHTML;
newApp.ActiveDocument.SaveAs(ref TargetPath, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
newApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
newApp.Quit();
File.Move(Sourcepath.ToString(), dirTar + filename);
MessageBox.Show("Done ");
}
else
{
Directory.CreateDirectory(@"C:\CONVERT\DOC FILES");
object TargetPath = @"C:\CONVERT\DOC FILES\" + filenoext;
object Unknown = Type.Missing;
Word.Documents d = newApp.Documents;
Word.Document od = d.Open(ref Sourcepath, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown, ref Unknown);
object format = Word.WdSaveFormat.wdFormatHTML;
newApp.ActiveDocument.SaveAs(ref TargetPath, ref format,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown, ref Unknown,
ref Unknown, ref Unknown);
newApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges);
newApp.Quit();
File.Move(Sourcepath.ToString(), dirTar + filename);
MessageBox.Show("Done ");
}
}
}
catch (Exception ConvertError)
{
MessageBox.Show("Error Description : " + ConvertError);
}
}
else
{
MessageBox.Show("Documents not found !");
}
}
}
}