Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Thu Sep 30, 2021 11:28 am

Hi

Please refer this file

Thank you

pr20080798
 
Posts: 149
Joined: Wed Jan 20, 2021 1:15 pm

Fri Oct 01, 2021 3:07 am

Hello,

Thanks for sharing more information!

Please refer to the following code to extract all attached files from the Word document you provided. Here I also attached the files I extract (two pictures and four documents).

Code: Select all
            //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);
                    }
                }

            }


Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Thu Oct 14, 2021 9:12 am

Hello,

Hope you're doing well!
How is your issue going? Did the code we provided work for you? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1651
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc