0

sample document I have code like this

internal void GetShapesInParagraph(int paragraphIndex)
{
  Application word = new Application();
  object miss = System.Reflection.Missing.Value;
  object path = @"A:\format1.docx";
  object readOnly = true;
  Document docs = word.Documents.Open(ref path, ref miss, ref readOnly, ref miss, ref miss,
                        ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref 
                 miss, ref miss, ref miss, ref miss);
  // get the paragraph we want to check
  Paragraph para = docs.Paragraphs[paragraphIndex];
  // validate the object
  if (para != null)
  {
      // the InlineShapes collection exists in the Range of that paragraph
      foreach (InlineShape ils in para.Range.InlineShapes)
      {
           // validate the object
           if (ils != null)
           {
               // validate this is a picture
               if (ils.Type == WdInlineShapeType.wdInlineShapePicture)
               {
                   DataRow dr = dt.NewRow();
                   // now we have a shape in that paragraph, we can do what we want to it
                   int ShapeWidth = Convert.ToInt32(ils.Width);
                   int ShapeHeight = Convert.ToInt32(ils.Height);
                   dr[0] = ils.PictureFormat;
                   dt.Rows.Add(dr);
                }
            }
        }
    }
}

I am able to import text from a doc/docx file but I'm stuck for images to be imported in datatable first and then in the gridview.

1 Answers1

0

You need to save the image to the disk and then read it back for getting a base64 string which can be stored in your database.

Consider using the Open XML SDK instead if you deal with open xml documents only. In that case you can read the image content from the disk and get the base64 string which can be stored in the Db, see Using base64 data stored in CustomXMLPart as image in Office for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45