Repost: Extract Embedded OLE Objects from Word

J

jcody

I would like to find a way to programmatically save embedded OLE objects
into a file folder from a Word document.

I have many Word documents that have many emails (and other files) embedded
within them, and I need to find a way to "extract" these embedded documents
and save them as files quickly.

One approach I've tried uses the Word object model to loop through the
InLineShapes collection. I can see that each of the embedded OLE objects
are in the collection.

// *** Begin: Sample Code ****************
using Microsoft.Office.Interop.Word;

foreach (InlineShape inlineShape in document.InlineShapes)
{
if (inlineShape.Type == WdInlineShapeType.wdInlineShapeEmbeddedOLEObject)
{
// Obtain the file name.
Trace.WriteLine("FileName: " +
Path.GetFileName(inlineShape.OLEFormat.IconLabel));
}
}
// *** End: Sample Code ****************

The problem is that I don't want to save the files by activating them.

Is there a way that I can save them directly to a file?

Thank you.
 
P

Peter Huang

Hi Jcody,

I am researching the issue and I will update you with new information ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi Jcody,

So far I am still researching the issue and I will update you with new
information ASAP.
Have a nice day!

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

Yan-Hong Huang[MSFT]

Hello Jcody,

Peter discussed with me on it. The issue is complicated. If you are still
monitoring this issue, could you please post another note to let me know
you are still there. Then we will contact office support team and
investigate this for you.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

JCody

Hello -

Yes - we are definitely still monitoring this issue. Please investigate - I look forward to a response.

Thank you,
JCody
 
Y

Yan-Hong Huang[MSFT]

Hi JCody,

Thanks for your quick response. We will contact Office support team on it
and reply here as soon as possible. I will email notify you when there is a
reply here.

Have a good day.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Y

Yan-Hong Huang[MSFT]

Hi JCody,

The issue is in office support team now. They are looking into it and will
get back here as soon as possible.

Thanks very much for your patience. If you have any more concerns, please
feel free to post here.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Joel Alley [MSFT]

It's important to note that the way a COM object stores its data when its
embedded can be different from the way it stores data in a file. The
proper way to extract such objects is to load the object in the associated
server (based on persisted CLSID), then ask the server to save the object
to file using IPersistFile (or IDispatch with dispid for SaveAs). The basic
steps you would need to follow are:

1) Use the StgOpenStorage API to retrieve an IStorage interface for the
Word document.
2) Use the IStorage::EnumElements method to find the embedded storages you
want.
3) For each storage you want, use the IStorage::Open Storage method to get
an IStorage pointer for it.
4) To determine the CLSID of the COM object that owns the IStorage, you
would call the "ReadClassStg" Windows API.
5) Use the CLSID to instantiate the COM object with a call to the
CoCreateInstance API.
6) Once you've instantiated the object, you call IUnknown::QueryInterface
for the IPersistStorage interface.
7) Call the IPersistStorage::Load interface to load the COM Object from the
storage.
8) Call IUnknown::QueryInterface on the COM object for the IPersistFile
interface.
9) Call IPersistFile::Save to save the COM object to a file.
10) Release all of the interfaces and close the COM object.
11) Start over at step 3 for the next storage you're interested in.

Thanks,
Joel Alley,MCSD
Microsoft Developer Support

Please post questions to the newsgroup; everyone benefits.
This posting is provided "AS IS" with no warranties, and confers no rights.
Sample code subject to http://www.microsoft.com/info/cpyright.htm
 
Y

Yan-Hong Huang[MSFT]

Hi JCody,

Good. If there is any question, please feel free to post here.

Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
-http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.as
p&SD=msdn

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top