473,503 Members | 12,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

7 New Member
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 72423
Began
3 New Member
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
vijayat23
7 New Member
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
blogged
1 New Member
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 Recognized Expert Contributor
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 New Member
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 New Member
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
GanesanRamasamy
5 New Member
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

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

Similar topics

1
2979
by: Vikas Kumar | last post by:
how to open word document and pdf file in aspx page
0
3195
by: Niyazi | last post by:
Hi, I created application that store the data in SQL SERVER that reside on network. The client also use this application to access the resources provided with application. But is the client want...
2
9042
by: Alan T | last post by:
In my C# application, I want to open a Word document using the code from the Help: using Microsoft.Office.Interop.Word; object readOnly = true; object fileName = @"C:\Test\NewDocument.doc"; ...
10
2054
by: Antoine De Groote | last post by:
Hi there, I have a word document containing pictures and text. This documents holds several 'ABCDEF' strings which serve as a placeholder for names. Now I want to replace these occurences with...
2
5244
by: sbettadpur | last post by:
hello everybody, i want to open word document file in browser, it means there will be one hyperlink if i click(ex: it's file.doc) on that it has to open the file in the browser. thanks
2
3801
by: alok5505 | last post by:
Hi All , I am new to Mobile development. I want to open word document in mobile control. Also I should be able to edit and save it. Is it possible to do it ? I am using Microsoft .NET...
1
6551
by: shanmugamit | last post by:
i want open word document in frame but its ask open or save file..not open in frame....here is my code <frameset cols="120,*"> <frame src='sample.html'> <frame name='openfile' src='sample.doc'>...
7
3991
by: Peter | last post by:
ASP.NET 2.0 I am trying to open a Word document and Excel document from a dialog web page, what's the best way to do that? I have tried the following: Response.Clear();...
7
6756
by: Peter | last post by:
I have the following code which is executed from a modal web page - it works fine on most, but on some computers the Word loads into memory but never displays. This occurs with IE6 and IE7, but...
2
4419
by: saketmayur | last post by:
Hi , I have write the following code to open word document on server using Microsoft.Office.Interop.Word; string DocPath = System.Configuration.ConfigurationManager.AppSettings; ...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5562
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.