No after adding this also its not working. Any how i got the solution for this. Following code will convert document with images into html file.
protected void Upload(object sender, EventArgs e)
{
object missingType = Type.Missing;
object readOnly = true;
object isVisible = false;
object documentFormat = 8;
string randomName = DateTime.Now.Ticks.ToString();
object htmlFilePath = Server.MapPath("~/Display Word Document in web/Temp/") + randomName + ".htm";
string directoryPath = Server.MapPath("~/Display Word Document in web/Temp/") + randomName + "_files";
//Upload the word document and save to Temp folder
FileUpload1.SaveAs(Server.MapPath("~/Display Word Document in web/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));
object fileName = Server.MapPath("~/Display Word Document in web/Temp/") + FileUpload1.PostedFile.FileName;
//Open the word document in background
ApplicationClass applicationclass = new ApplicationClass();
applicationclass.Documents.Open(ref fileName,
ref readOnly,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref isVisible,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;
//Save the word document as HTML file
document.SaveAs(ref htmlFilePath, ref documentFormat, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType);
//Close the word document
document.Close(ref missingType, ref missingType, ref missingType);
//Read the Html File as Byte Array and Display it on browser
string filePath = htmlFilePath.ToString();
string searchText = randomName;
string replaceText = "Temp\\" + randomName;
ReplaceInFile(filePath, searchText, replaceText);
byte[] bytes;
using (FileStream fs = new FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read))
{
BinaryReader reader = new BinaryReader(fs);
bytes = reader.ReadBytes((int)fs.Length);
fs.Close();
}
Response.BinaryWrite(bytes);
Response.Flush();
FileUpload1.Visible = false;
btnUpload.Visible = false;
//Delete the Html File
//File.Delete(htmlFilePath.ToString());
//foreach (string file in Directory.GetFiles(directoryPath))
//{
// File.Delete(file);
//}
//Directory.Delete(directoryPath);
//Response.End();
//Delete the Uploaded Word File
//File.Delete(Server.MapPath("~/Display Word Document in web/Temp/") + Path.GetFileName(FileUpload1.PostedFile.FileName));
}
private void ReplaceInFile(string filePath, string searchText, string replaceText)
{
StreamReader reader = new StreamReader(filePath);
string content = reader.ReadToEnd();
reader.Close();
content = Regex.Replace(content, searchText, replaceText);
StreamWriter writer = new StreamWriter(filePath);
writer.Write(content);
writer.Close();
}