By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,959 Members | 2,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,959 IT Pros & Developers. It's quick & easy.

Open Word document error

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.