473,654 Members | 3,089 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 72449
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
3006
by: Vikas Kumar | last post by:
how to open word document and pdf file in aspx page
0
3222
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 to register new customer or companies they will enter the information in Windows Form and the program automaticaly creates the WORD document under specific folder under application path. Once the empty word file created than ask user if they want...
2
9050
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"; this.Application.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
10
2069
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 names in a list (members). I open both input and output file in binary mode and do the transformation. However, I can't open the resulting file, Word just telling that there was an error. Does anybody what I am doing wrong? Oh, and is this...
2
5284
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
3807
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 compact framework with Visual studio 2005. Thanks and Regards
1
6578
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'> </frameset>
7
4003
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(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
7
6781
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 always works on FireFox. When I close the modal web page Word disappears from Memory. I don't know where the problem is, my code, IE setup or intranet security, I also do not know where and for what to look for - I've tried Google but I don't know...
2
4427
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; ApplicationClass wordApp = new ApplicationClass(); string filePath = ""; filePath = DocPath + Session + "/" + DocFile.Value.ToString();
0
8379
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.