PDA

View Full Version : Error opening word file from Asp.net


vyasdev2005
04-22-2009, 08:58 AM
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 = "G:\\WordSampleCompiled\\SQL Server 2005 Installation.doc";
object fileName = Server.MapPath("/WordSample/WordFiles/Test.doc");
object readOnly = false;
object isVisible = true;
// Here is the way to handle parameters you don't care about in .NET
object missing = System.Reflection.Missing.Value;
// Make word visible, so you can see what's happening
WordApp.Visible = true;
// Open the document that was chosen by the dialog
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);
// Activate the document so it shows up in front
aDoc.Activate();
// Add the copyright text and a line break
WordApp.Selection.TypeText("Copyright C# Corner");
WordApp.Selection.TypeParagraph();
}


And this code for Opening file,


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. I am using Visual Studio 2008. and MS Office 2007 for this, Is this error in giving file path or something else?