470,810 Members | 1,172 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

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
Aug 7 '06 #1
7 71722
Began
3
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:

Expand|Select|Wrap|Line Numbers
  1. private Word.ApplicationClass WordApp = new Word.ApplicationClass();
  2.  
  3.  
  4. if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
  5.   {
  6.      object fileName = openFileDialog1.FileName;
  7.      object readOnly = false;
  8.  
  9.        object isVisible = true;
  10.        object missing = System.Reflection.Missing.Value;
  11.        WordApp.Visible = true;
  12.  
  13.       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);
  14.  
  15.         aDoc.Activate();
  16.  
  17. }
regards,
Began.
Aug 7 '06 #2
I did every thing what u given code, but runtime it throws an error " Could not open macro storage "
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:
Expand|Select|Wrap|Line Numbers
  1. private Word.ApplicationClass WordApp = new Word.ApplicationClass();
  2.  
  3.  
  4. if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
  5.   {
  6.      object fileName = openFileDialog1.FileName;
  7.      object readOnly = false;
  8.  
  9.        object isVisible = true;
  10.        object missing = System.Reflection.Missing.Value;
  11.        WordApp.Visible = true;
  12.  
  13.       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);
  14.  
  15.         aDoc.Activate();
  16.  
  17. }
regards,
Began.
Aug 7 '06 #3
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.
Sep 21 '06 #4
radcaesar
759 Expert 512MB
Hi,

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

use dcomcnfg.msc
Sep 21 '06 #5
sandu
2
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.
Sep 21 '06 #6
longia
1
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.
Sep 28 '06 #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.
Expand|Select|Wrap|Line Numbers
  1. if( Request.QueryString["strFile"] != null )
  2. {
  3.   string strFilePath1="";
  4.   string strFileName = Request.QueryString["strFile"].ToString();
  5.   strFilePath1=Request.PhysicalApplicationPath+"/BackOffice/Catalogue/UploadFiles/"+strFileName;
  6.   if(strFileName!="")
  7.   {
  8.     Response.ContentType=strFilePath1;
  9.     Response.AddHeader("content-disposition", "attachment;filename="+strFileName);
  10.     Response.WriteFile(strFilePath1);                                
  11.   }
  12. }


Regards,

R.Ganesan
Sep 29 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Vikas Kumar | last post: by
2 posts views Thread by Alan T | last post: by
10 posts views Thread by Antoine De Groote | last post: by
7 posts views Thread by Peter | last post: by
7 posts views Thread by Peter | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.