469,964 Members | 1,609 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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 8881
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Vikas Kumar | 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
1 post views Thread by rainxy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.