I am able to not get the embedded OLE object file name for few files in the Word Document.'I am not able to get the File Name when shape.OleFormat.IconCaption is empty or null.
I came to know we can read from shape.ImageData.ImageBytes. Can any one guide me how to read the file name.Please help
public void Extract(string SourceFile, string DestinationFolder)
{
Document doc = new Document();
License wordsLicense = new License();
string licenseFileName = "Aspose.Total.Product.Family.lic";
wordsLicense.SetLicense(licenseFileName);
doc = new Document(SourceFile);
NodeCollection shapes = doc.GetChildNodes(NodeType.Shape, true);
int i = 0; string FileName = string.Empty;
foreach (Shape shape in shapes)
{
if (shape.OleFormat != null)
{
if (!shape.OleFormat.IsLink)
{
// 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 "Excel.SheetMacroEnabled.12":
ext = ".xlsm";
break;
case "PowerPoint.Show.8":
ext = "ppt";
break;
case "PowerPoint.Show.12":
ext = "pptx";
break;
case "AcroExch.Document.7":
ext = "pdf";
break;
case "Word.Document.8":
ext = "doc";
break;
case "Word.Document.12":
ext = "docx";
break;
case "Visio.Drawing.11":
ext = "docx";
break;
default:
ext = "jpg";
break;
}
if (!string.IsNullOrEmpty(shape.OleFormat.IconCaption))
{
FileName = shape.OleFormat.IconCaption;
shape.OleFormat.Save(String.Format(DestinationFolder + "/{0}", FileName));
}
else
{
byte[] imageName = shape.ImageData.ImageBytes;
FileName = i.ToString();
shape.OleFormat.Save(String.Format(DestinationFolder + "/out_{0}.{1}", FileName, shape.OleFormat.SuggestedExtension));
}
}
else if (shape.OleFormat.IsLink)
{
string filePath = shape.OleFormat.SourceFullName;
string fileName = shape.OleFormat.IconCaption;
// FileStream file = File.Create(DestinationFolder + "/" + fileName);
// byte[] data = shape.OleFormat.Save(;
// file.Write(data, 0, data.Length);
// file.Close();
}
i++;
}
}
}