Hi
Please refer this file
Thank you
//Load document
Document document = new Document(@"J:\test\samplefile\samplefile.docx");
List<DocOleObject> oles = new List<DocOleObject>();
List<DocPicture> pictures = new List<DocPicture>();
//loop section
foreach (Section section in document.Sections)
{
foreach (Paragraph paragraph in section.Paragraphs)
{
//get all pictures
foreach (DocumentObject docObject in paragraph.ChildObjects)
{
if (docObject.DocumentObjectType == DocumentObjectType.Picture)
{
pictures.Add(docObject as DocPicture);
}
}
//remove ole icon picture from picture list
//get all ole
foreach(DocumentObject docObject in paragraph.ChildObjects)
{
if (docObject.DocumentObjectType == DocumentObjectType.OleObject)
{
oles.Add(docObject as DocOleObject);
DocPicture OLEpicture = (docObject as DocOleObject).OlePicture;
if (pictures.Contains(OLEpicture))
{
pictures.Remove(OLEpicture);
}
}
}
}
}
//save picture to file
for(int i =0; i< pictures.Count; i++)
{
pictures[i].Image.Save(string.Format("image_{0}.png", i), System.Drawing.Imaging.ImageFormat.Png);
}
//save all oles
foreach(DocOleObject Ole in oles)
{
string s = Ole.ObjectType;
//If s == "AcroExch.Document.DC", means it's a PDF document
if (s == "AcroExch.Document.DC")
{
File.WriteAllBytes("Result.pdf", Ole.NativeData);
}
//If s == "Excel.Sheet.12", means it's an Excel workbook
else if (s == "Excel.Sheet.12")
{
File.WriteAllBytes("Result.xlsx", Ole.NativeData);
}
//If s == "PowerPoint.Show.12", means it's a PowerPoint File
else if (s == "PowerPoint.Show.12")
{
File.WriteAllBytes("PPTResult.pptx", Ole.NativeData);
}
//If s == "Word.Document.12", means it's a Word document
else if (s == "Word.Document.12")
{
File.WriteAllBytes("WordResult.docx", Ole.NativeData);
}
//Package
else if (s == "Package")
{
string fileName = Ole.PackageFileName;
string extension = fileName.Substring(fileName.LastIndexOf("."));
if (extension.Equals(".exe"))
{
}
else if (extension.Equals(".dll"))
{
File.WriteAllBytes("DllResult.dll", Ole.NativeData);
}
}
}