Opening a word document in asp.net.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • s14m27
    New Member
    • Jul 2007
    • 14

    Opening a word document in asp.net.

    Hi.

    I have saved word documents in my application folder. how do i open them on button click?
    i have used the following code.But it is opening in the same browser :

    Response.Append Header("Content-Type", "applicatio n/msword");
    Response.Clear( );
    Response.Conten tType = "applicatio n/msword".ToStrin g();
    Response.AddHea der("Content-Disposition", "inline;filename=" + txtUName.Text + ".doc");
    Response.Charse t = "";
    this.EnableView State = false;
    Response.WriteF ile("E:\\TEACHE R\\Resumes\\" + txtUName.Text + ".doc");
    Response.End();
    I have tried using "attachment " instead of "inline" to open it as an attachment. But failed to do so...
    could anyone help?????

    Thanks a lot!!!!!
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    Please refer this link
    Link

    Originally posted by s14m27
    Hi.

    I have saved word documents in my application folder. how do i open them on button click?
    i have used the following code.But it is opening in the same browser :

    Response.Append Header("Content-Type", "applicatio n/msword");
    Response.Clear( );
    Response.Conten tType = "applicatio n/msword".ToStrin g();
    Response.AddHea der("Content-Disposition", "inline;filename=" + txtUName.Text + ".doc");
    Response.Charse t = "";
    this.EnableView State = false;
    Response.WriteF ile("E:\\TEACHE R\\Resumes\\" + txtUName.Text + ".doc");
    Response.End();
    I have tried using "attachment " instead of "inline" to open it as an attachment. But failed to do so...
    could anyone help?????

    Thanks a lot!!!!!

    Comment

    • polkmn
      New Member
      • Mar 2008
      • 2

      #3
      Word.Applicatio nClass WordApp = new Word.Applicatio nClass();
      //object fileName = openFileDialog1 .FileName;
      //string Path = d.FullName +"\\"+ fi[i].Name;
      object fileName = d.FullName + "\\" + fi[i].Name;
      object Confirm = false;
      object readOnly = true; ;
      object isVisible = true;
      object addtorec = false;
      object oprep = true;
      object missing = System.Reflecti on.Missing.Valu e;
      Word.Document wDoc = WordApp.Documen ts.Open(ref fileName, ref Confirm, ref readOnly, ref addtorec, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref oprep, ref missing, ref missing, ref missing);
      // Here is the way to handle parameters you don't care about in .NET
      wDoc.Activate() ;

      Comment

      Working...