ProAnswers.org

How to convert a doc file into html by using aspnet?

For converting doc file into html using asp.net we must have MS Word installed on the same server where ASP.NET is running. After this you can make reference to particular ASP.NET project. You can find Word library by following steps:

In Solution window -> you can find your project -> then right-click on it -> now choose “Add Reference”-> click on COM tab -> now get Microsoft Word 11 Object Library ->select it -> now press OK

After this you can use “Word” namespace.Now upload your file in sample webpage.

try this code:

protected void B1(object s, EventArgs e)
{
if (FileUpload1.HasFile)
{

string FTSI = @“c: emp\doc”;
string FP = folder_to_save_in + FileUpload1.FileName;

FileUpload1.SaveAs(FP);

Word.ApplicationClass wordApplication = new Word.ApplicationClass();

object oNO = System.Reflection.Missing.Value;
object oFP = FP;
Word.Document doc = wordApplication.Documents.Open(ref oFP,
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO,
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO,
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO);

string newfilename = folder_to_save_in + FileUpload1.FileName.Replace(".doc", “.html”);
object oNF = newfilename;
object oFR = Word.WdSaveFormat.wdFormatHTML;
object oEN = Microsoft.Office.Core.MsoEncoding.msoEncodingUTF8;
object oEN = Word.WdLineEndingType.wdCRLF;

wordApplication.ActiveDocument.SaveAs(ref oNF, ref oFR, ref oNO,
ref oNO, ref oNO, ref oNO, ref oNO, ref oNO, ref oNO,
ref oNO, ref oNO, ref oNO, ref oNO,
ref oNO, ref oNO, ref oNO);

Label1.Text = “Uploaded file successfully!”;

doc.Close(ref oNO, ref oNO, ref oNO);
}
}