Solved

How to get a byte array of a MS  Word document using C++ /  MFC

Posted on 2007-04-10
5
589 Views
Last Modified: 2013-11-20
Using C++ and ATL in MS Word 2003, how can I get a byte array of the entire current document to put into a database.  Yes, I know the filesize issue. I know how to embed into the database, but not sure how to get the byte array without first saving ther document.

Thanks!
0
Comment
Question by:craig20120
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 11

Expert Comment

by:DeepuAbrahamK
ID: 18887344
May be this MS word automatioin would help you: read this link
http://www.codeproject.com/com/MSWACPP.asp

Best Regards,
DeepuAbrahamK
0
 

Author Comment

by:craig20120
ID: 18889109
Thanks for the suggestion.  I know how to parse a document, I need to actually get a pointer to the entire contents of the document so if I emdedded the contents of that pointer in my database it is the actually Word document.  
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 18900186
>>>> I need to actually get a pointer to the entire contents of the document
Do you need text only (A) or the document as an embedded OLE object (B) or the contents of the binary doc file as a BLOB in the database (C).

A and B can be made by using automation. Your DBMS should be able to store embedded OLE objects (MS ACCESS SQL SERVER) for B. C can be made by retrieving the file size by calling stat, allocating a buffer which is big enough to store the fie, opening the doc file in binary mode, reading the file to the buffer, storing the buffer as a BLOB:

       struct stat status = { 0 };
       if (stat("mydoc.doc", &status) == 0)
       {
              ifstream ifs("mydoc.doc", ios::in | ios::binary);
              char buf = new char[status.st_size];
              if (ifs.read(buf, status.st_size))
              {
                     ifs.close();
                     // store buf to dtabase
              }
         
             
       }

>>>> Yes, I know the filesize issue.
What is the filesize issue?

>>>> I know how to embed into the database
If you know where is the problem?

>>>> but not sure how to get the byte array
If embedding OLE objects you don't need to care for the byte array yourself.

>>>> without first saving ther document.
Why saving??? Isn't the document saved yet? Do you want to get the document while it isn't saved?

Regards, Alex

0
 

Author Comment

by:craig20120
ID: 18903347
Evening Alex, either B or C would be good.  I have figured out how to copy the complete document to the clipboard, get the embeded object and then save it to my database. I would perfer to do C though Yes, without saving the document to the disk first.

It sounds like B is dealing with the embeded object like using the clipboard to.  Wondering if this way would be more straight forward though???
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 350 total points
ID: 18905132
>>>> I would perfer to do C though Yes, without saving the document to the disk first.
Hmmm. Don't think it worked. The temporary save can't be used cause it is exclusively opened and it's contents doesn't need to be up-to-date. So, the only chance is to use automation to make a 'Save As...', read the file and delete it after read.

Regards, Alex
 
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question