I am trying to opening Word file in asp.net application. I Try Following Code For That

private Word.ApplicationClass WordApp = new Word.ApplicationClass();
    protected void Button1_Click(object sender, EventArgs e)
        object fileName = Server.MapPath("/WordSample/WordFiles/Test.doc");
        object readOnly = false;
        object isVisible = true;
        object missing = System.Reflection.Missing.Value;
        WordApp.Visible = true;
        Word.Document aDoc = WordApp.Documents.Open(ref fileName, ref missing, 

ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, 

ref missing, ref missing, ref missing, ref isVisible,ref missing,ref 

missing,ref missing,ref missing);
        WordApp.Selection.TypeText("Copyright C# Corner");

All this works fine in View In Browser, But when I publish that Page The file

not opening and on Click of Button, Browser running continuosly, but cant find file. Is this error with path or else?

change this line

object fileName = Server.MapPath("/WordSample/WordFiles/Test.doc");


object fileName = Server.MapPath("~") & "WordSample\WordFiles\Test.doc";

TRY TO WRITE THE VALUE OF Server.MapPath("WordFiles") then check with path then print whole file path then check with server.

This article has been dead for over six months. Start a new discussion instead.