I have a word file which can contain any type of embeded objects. I need to write a code, in any form(windows, ASP.NET, c# or VB) whatever it may be, but i should read the objects inside the word file and save it to my harddrive. My production deployment
is stopped due to this.
Any help is appreciated and its really very very very urgent for me. Please help
So No one gave me an answer here. I did a lot of Binging and googling and finally found the answer(atleast useful for others)
This can be easily acheived using aspose.words dll.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Drawing;
using Aspose.Words.Fields;
namespace ExtractFromword
{
public class Extractfromword
{
public void Extract(string SourceFile, string DestinationFolder)
{
Aspose.Words.Document doc = new Aspose.Words.Document();
doc = new Aspose.Words.Document(SourceFile);
Aspose.Words.NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0;
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
// Get extension of th eOL object.
string ext = "object";
switch (shape.OleFormat.ProgId)
{
case "Excel.Sheet.8":
ext = "xls";
break;
case "Excel.Sheet.12":
ext = "xlsx";
break;
case "AcroExch.Document.7":
ext = "pdf";
break;
case "Word.Document.8":
ext = "doc";
break;
case "Word.Document.12":
ext = "docx";
break;
default:
ext = "jpg";
break;
}
shape.OleFormat.Save(String.Format(DestinationFolder + "/out_{0}.{1}", i, ext));
i++;
}
}
}
}
}
Marked as answer by speedriser on Apr 27, 2011 06:30 AM
speedriser
Member
42 Points
28 Posts
How to read a embeded object in a word file and save it to hardrive`
Apr 26, 2011 06:24 AM|LINK
I have a word file which can contain any type of embeded objects. I need to write a code, in any form(windows, ASP.NET, c# or VB) whatever it may be, but i should read the objects inside the word file and save it to my harddrive. My production deployment is stopped due to this.
Any help is appreciated and its really very very very urgent for me. Please help
speedriser
Member
42 Points
28 Posts
Re: How to read a embeded object in a word file and save it to hardrive`
Apr 27, 2011 01:34 AM|LINK
Its so strange that none of the ASP Moderators or forums kings are able to answer my question. Guys please help me out. Am still struggling with it
speedriser
Member
42 Points
28 Posts
Re: How to read a embeded object in a word file and save it to hardrive`
Apr 27, 2011 05:53 AM|LINK
So No one gave me an answer here. I did a lot of Binging and googling and finally found the answer(atleast useful for others)
This can be easily acheived using aspose.words dll.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using Aspose.Words; using Aspose.Words.Tables; using Aspose.Words.Drawing; using Aspose.Words.Fields; namespace ExtractFromword { public class Extractfromword { public void Extract(string SourceFile, string DestinationFolder) { Aspose.Words.Document doc = new Aspose.Words.Document(); doc = new Aspose.Words.Document(SourceFile); Aspose.Words.NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true); int i = 0; foreach (Shape shape in shapes) { if (shape.OleFormat != null) { // Get extension of th eOL object. string ext = "object"; switch (shape.OleFormat.ProgId) { case "Excel.Sheet.8": ext = "xls"; break; case "Excel.Sheet.12": ext = "xlsx"; break; case "AcroExch.Document.7": ext = "pdf"; break; case "Word.Document.8": ext = "doc"; break; case "Word.Document.12": ext = "docx"; break; default: ext = "jpg"; break; } shape.OleFormat.Save(String.Format(DestinationFolder + "/out_{0}.{1}", i, ext)); i++; } } } } }