none
retreiving data from content control word 2007 + Openxml RRS feed

  • Question

  • Hi,
    i refer to this following article
    http://msdn.microsoft.com/en-us/library/bb879915.aspx

    Would like to know what is best practice to retrieve the data from the placeholders?

    1. Activex VBA
    2. Open XML?

    my scenario i just want to extract data for only one time, i dont want to rely on create xml datastore and binding elements.

    Please provide me direction,

    Thanks in advance,
    Sahridhayan
    Monday, August 24, 2009 3:25 PM

Answers

All replies

  • Take a look at the following blog post for sample code on finding specific content controls in Open XML: http://blogs.msdn.com/brian_jones/archive/2008/12/08/the-easy-way-to-assemble-multiple-word-documents.aspx

    Let us know if you run into any issues or questions?

    Zeyad Rajabi (MS)
    Zeyad Rajabi (MS)
    • Marked as answer by sahridhayan Tuesday, September 1, 2009 7:05 AM
    Monday, August 24, 2009 8:33 PM
  • Hi

    i tried the same but not successful after 1st element. see the following i have two content control with different names, i was trying to search the element,
    now getting error "Sequence contains no elements"    at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       at docxTest.Form1.LoadFile() in y:\Projects\CAO\eSRF\docxTest\docxTest\docxTest\Form1.cs:line 57

    		sdtName = "testCtrl";
                        
               
                        
                        SdtBlock sdt = mainPart.Document.Descendants<SdtBlock>()
                                    .Where(s => s.GetFirstChild<SdtProperties>().GetFirstChild<Alias>().Val.Value
                                    .Equals(sdtName)).First();
                       // .Contains(s.SdtProperties.GetFirstChild<Alias>().Val.Value))
    
                        MessageBox.Show(sdt.InnerText);
    
                        sdtName = "test2Ctrl";
                        sdt = mainPart.Document.Descendants<SdtBlock>()
                                    .Where(s => s.GetFirstChild<SdtProperties>().GetFirstChild<Alias>().Val.Value
                                    .Equals(sdtName)).First();
                        MessageBox.Show(sdt.InnerText);
    Hope i am missing some thing simple. please revert back to me. if you find some thing different...

    Thank you,
    Sahridhayan
    Tuesday, August 25, 2009 10:37 AM
  • zeyad rajabi,

    thanks for the information, it works for creating new document from scratch.
    if we have lot of controls and contents, there is scenario gives the error, it cannot find control some sequence error.

    thanks,

    sahridhayan

    Tuesday, September 1, 2009 7:07 AM