0

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)
    {
        Installation.doc";
        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);
        
        aDoc.Activate();
        
        WordApp.Selection.TypeText("Copyright C# Corner");
        WordApp.Selection.TypeParagraph();
    }

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?

3
Contributors
5
Replies
6
Views
8 Years
Discussion Span
Last Post by mail2saion
0

change this line

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

to

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

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.