473,544 Members | 1,149 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Document.Open Office Example

Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);

worddoc.Activat e();
wordapp.Selecti on.TypeText("TE EEEEEEEEEEEEEEE EEEEEEEEEEEEEEE EST");
wordapp.Selecti on.TypeParagrap h();
worddoc.Save();
wordapp.Documen ts.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian
Jan 16 '06 #1
4 18626
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Fabian" <Fa****@discuss ions.microsoft. com> wrote in message
news:96******** *************** ***********@mic rosoft.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activat e();

wordapp.Selecti on.TypeText("TE EEEEEEEEEEEEEEE EEEEEEEEEEEEEEE EST");
wordapp.Selecti on.TypeParagrap h();
worddoc.Save();
wordapp.Documen ts.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian

Jan 16 '06 #2
Fabian,
you need to ensure the document actually exists at the path specified, and
that you have all upper and lower casing exact.
For example, this path:

object path = "C:\\temp\\Test .doc";

would open "Test.doc" from the C:\temp folder.
--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Fabian" wrote:
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);

worddoc.Activat e();
wordapp.Selecti on.TypeText("TE EEEEEEEEEEEEEEE EEEEEEEEEEEEEEE EST");
wordapp.Selecti on.TypeParagrap h();
worddoc.Save();
wordapp.Documen ts.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian

Jan 16 '06 #3
Hi,

Error :

ComException was Unhandled
Exception from HRESULT: 0x800A1436

and it occurs in this line :

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);
The Variables are implemented in this way :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_missing = Type.Missing;
The Doc Data was generated by a Crystal Report, but now i must add an Image
to the Document, because my CR Version does not allow dynamic Image Data
Sources. So I generate an CR, save it in Word. And now I want to open this
Word Document, and insert the Image.
I hope that this is possible.

But I cant open the DOC File. The CR is closed before, the Filename is
right. I dont know where my mistake is.

Please help me (and sorry for my english)

Greets

Fabian
"Nicholas Paldino [.NET/C# MVP]" wrote:
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Fabian" <Fa****@discuss ions.microsoft. com> wrote in message
news:96******** *************** ***********@mic rosoft.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activat e();

wordapp.Selecti on.TypeText("TE EEEEEEEEEEEEEEE EEEEEEEEEEEEEEE EST");
wordapp.Selecti on.TypeParagrap h();
worddoc.Save();
wordapp.Documen ts.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian


Jan 17 '06 #4
Sorry, I forgot to say :

I use
VS2005.NET C#
Office2003
Windows2000


"Fabian" wrote:
Hi,

Error :

ComException was Unhandled
Exception from HRESULT: 0x800A1436

and it occurs in this line :

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing);
The Variables are implemented in this way :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_missing = Type.Missing;
The Doc Data was generated by a Crystal Report, but now i must add an Image
to the Document, because my CR Version does not allow dynamic Image Data
Sources. So I generate an CR, save it in Word. And now I want to open this
Word Document, and insert the Image.
I hope that this is possible.

But I cant open the DOC File. The CR is closed before, the Filename is
right. I dont know where my mistake is.

Please help me (and sorry for my english)

Greets

Fabian
"Nicholas Paldino [.NET/C# MVP]" wrote:
Fabian,

What is the error and what line does it occur on?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Fabian" <Fa****@discuss ions.microsoft. com> wrote in message
news:96******** *************** ***********@mic rosoft.com...
Hello,

I want to open a Word Document in my C# Programm. I tried this :

Word.Applicatio n wordapp = new Word.Applicatio n();
object path = "TEST.DOC";
object vk_read_only = false;
object vk_visible = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;

object vk_missing = Type.Missing;

Word.Document worddoc = wordapp.Documen ts.Open(ref path, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref
vk_missing,
ref vk_missing);

worddoc.Activat e();

wordapp.Selecti on.TypeText("TE EEEEEEEEEEEEEEE EEEEEEEEEEEEEEE EST");
wordapp.Selecti on.TypeParagrap h();
worddoc.Save();
wordapp.Documen ts.Close(ref vk_missing, ref vk_missing, ref
vk_missing);
But this does not work, an Error oucurs since the Document.Open is done.
Where is my mistake ?

Please help me

Fabian


Jan 17 '06 #5

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

Similar topics

3
2770
by: Emily John | last post by:
I have a word document that I need to send it as an attachment to an XML file. Basically, converting into byte array or using some encoding mechanism. This has to be done through XML serialization in c#. Is it possible to do it through xml serialization ? THanks, --Emily *** Sent via Developersdex http://www.developersdex.com *** Don't...
8
9137
by: Asma | last post by:
Dear Sir, I am trying to find a way to open a Word document using C language and read the text of word doc into a variable. (Turbo C on Dos 6.0). Can anyone please tell me which libraries in C can be used to perform this task. Thanks you so much
1
3640
by: Marco Moioli | last post by:
Hi, I have a problem with a X509 digital signature. I want to sign a Word 2003 document saved in .xml format. the problem is that after the signature, Word 2003 don't want to open the document. If I apply a standard W3C signature to an Xml file wrote in Word 2003 I obtain: <?mso-application progid="Word.Document"?> <w:wordDocument
1
13913
by: Gary | last post by:
Hi, there, 1. I would like to open a word document in a MDI environment. Every time, a new window outside my MDI poped out and show the word document. Is there a method I can use to specify the showing window? And how to? 2. Is there a way to preview the word document, other than load it fully? 3. How to extract all the characters in...
4
2418
by: Jon Westmore | last post by:
I'm using an ASP page to dynamically generate an XML document using a data source. I was thinking the concept would be similar to dynamically creating HTML but I'm running into an issue. Here is my source code: <%Response.ContentType = "text/xml" Response.CharSet="" Dim Connect ,RS, Query, Details Details = Trim(Request("Details"))
0
1346
by: Karel | last post by:
Hi, I have developed a vb.net application to create a mail-merged document by using Automation to word from VB.NET. I added the following reference to the application: Microsoft Office 10.0 Object Library In runtime, when I click that button, I open a word doc. I create a commandbar whith in that commandbar a combobox with a list of...
0
8651
southoz
by: southoz | last post by:
Good ay all , I'm fairly new to access(a little over 5 weeks now). Since I'v started I have picked up a lot of useful information from forums such as this and in doing so will share that information with others. I have seen many request for information on mail merging an how to send data to word documents this is something I have put together...
9
3079
by: tubby | last post by:
Silly question, but here goes... what's a good way to determine when a file is an Open Office document? I could look at the file extension, but it seems there would be a better way. VI shows this info in the files: mimetypeapplication/vnd.oasis.opendocument.textPK mimetypeapplication/vnd.oasis.opendocument.presentationPK etc. Not really...
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; ApplicationClass wordApp = new ApplicationClass(); string filePath = ""; filePath = DocPath + Session + "/" +...
0
7429
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...
0
7368
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...
1
7384
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...
0
5916
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5301
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4922
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3414
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1844
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
671
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...

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.