How to open word document in asp.net with C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vijayat23
    New Member
    • Jul 2006
    • 7

    How to open word document in asp.net with C#

    i have problem in opening the word document , it shows an error like could not open macro storage, please help me , thanks in advance
  • Began
    New Member
    • Aug 2006
    • 3

    #2
    hi,

    here is the code to open the word document.


    add a COM reference to your project by right clicking in the solution explorer on References->Add Reference

    Click on the COM tab and look for the Microsoft Word 9.0 Object Library

    just declare the line below in your class:

    Code:
    private Word.ApplicationClass WordApp = new Word.ApplicationClass();
    
    
    if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
      {
         object fileName = openFileDialog1.FileName;
         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);
    
            aDoc.Activate();
    
    }
    regards,
    Began.
    Last edited by Frinavale; Dec 9 '09, 07:43 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

    Comment

    • vijayat23
      New Member
      • Jul 2006
      • 7

      #3
      I did every thing what u given code, but runtime it throws an error " Could not open macro storage "
      Originally posted by Began
      hi,

      here is the code to open the word document.


      add a COM reference to your project by right clicking in the solution explorer on References->Add Reference

      Click on the COM tab and look for the Microsoft Word 9.0 Object Library

      just declare the line below in your class:
      Code:
      private Word.ApplicationClass WordApp = new Word.ApplicationClass();
      
      
      if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
        {
           object fileName = openFileDialog1.FileName;
           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);
      
              aDoc.Activate();
      
      }
      regards,
      Began.

      Comment

      • blogged
        New Member
        • Sep 2006
        • 1

        #4
        Originally posted by vijayat23
        I did every thing what u given code, but runtime it throws an error " Could not open macro storage "
        Did you get to solve this issue? If you have I am very interested to know how you did it because it is driving me nuts. I have tried everything I could possibly find on the website and more. Help please if you can.

        Comment

        • radcaesar
          Recognized Expert Contributor
          • Sep 2006
          • 759

          #5
          Hi,

          the account running the web app (network service) needs access to the Word COM object

          use dcomcnfg.msc

          Comment

          • sandu
            New Member
            • Sep 2006
            • 2

            #6
            as you said the user account under which runs the asp.net don't have enough rights to call in execution the MS Word. One way is of course to use dcomconfig enable the asp.net but what if somebodey tries to hack you? you should use impersonation because is more safe.

            Comment

            • longia
              New Member
              • Sep 2006
              • 1

              #7
              when we try to open word document with the help of code given by you, it does not open the information in header and footer. please help how we can read header and footer of the document also.

              Comment

              • GanesanRamasamy
                New Member
                • Sep 2006
                • 5

                #8
                Originally posted by longia
                when we try to open word document with the help of code given by you, it does not open the information in header and footer. please help how we can read header and footer of the document also.
                Code:
                if( Request.QueryString["strFile"] != null )
                {
                  string strFilePath1="";
                  string strFileName = Request.QueryString["strFile"].ToString();
                  strFilePath1=Request.PhysicalApplicationPath+"/BackOffice/Catalogue/UploadFiles/"+strFileName;
                  if(strFileName!="")
                  {
                    Response.ContentType=strFilePath1;
                    Response.AddHeader("content-disposition", "attachment;filename="+strFileName);
                    Response.WriteFile(strFilePath1);								
                  }
                }


                Regards,

                R.Ganesan
                Last edited by Frinavale; Dec 9 '09, 07:45 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.

                Comment

                Working...