473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Open Word document error

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,
ref missing, ref missing, ref missing, ref missing, ref missing);I got a
compilation error:'WindowsApplication2.Form1' does not contain a definition
for 'Application'


Sep 25 '06 #1
2 9033
You need to declare an instance of Word:

Microsoft.Office.Interop.Word.Application app = new
Microsoft.Office.Interop.Word.ApplicationClass();
object readOnly = true;
object fileName = @"C:\Test\NewDocument.doc";
app.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 missing, ref missing, ref missing, ref missing, ref missing);

HTH

Ciaran O'Donnell

"Alan T" wrote:
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,
ref missing, ref missing, ref missing, ref missing, ref missing);I got a
compilation error:'WindowsApplication2.Form1' does not contain a definition
for 'Application'


Sep 25 '06 #2
Hi,

What should I add to my Reference ?

"Ciaran O''Donnell" <Ci************@discussions.microsoft.comwrote in
message news:4A**********************************@microsof t.com...
You need to declare an instance of Word:

Microsoft.Office.Interop.Word.Application app = new
Microsoft.Office.Interop.Word.ApplicationClass();
object readOnly = true;
object fileName = @"C:\Test\NewDocument.doc";
app.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 missing, ref missing, ref missing, ref missing, ref missing);

HTH

Ciaran O'Donnell

"Alan T" wrote:
>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,
ref missing, ref missing, ref missing, ref missing, ref missing);I
got a
compilation error:'WindowsApplication2.Form1' does not contain a
definition
for 'Application'



Sep 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Vikas Kumar | last post by:
how to open word document and pdf file in aspx page
0
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...
10
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
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
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
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
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
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
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
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
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,...
0
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...

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.