Hello EveryOne,
I had a template(dotx) in 2010.i designed the table and in that table i added the contentcontrols. using the following code i replace the value in content control during runtime.In this case the Value of first contentcontrol are replace to all content control.
For ex: Contentcontrol1 = Test1, Contentcontrol2 = Test2, Contentcontrol3 = Test3.
But in Template it shows Contentcontrol1 =Test1, Contentcontrol2 = Test1, Contentcontrol3 = Test1.
I gave the unique name to each contentcontrol, but the values are duplicate. If i removed the table or move the contentcontrol out of table it works correct..
so please guide what wrong i did ... thank you..
var contentControls = wordDoc.MainDocumentPart .Document .Descendants<SdtRun>() .Where(s => s.SdtProperties.GetFirstChild<Alias>().Val.Value.ToString().Trim() == name); var sdt = new SdtContentRun(); Run r = new Run(); DocumentFormat.OpenXml.Wordprocessing.Text t; t = new DocumentFormat.OpenXml.Wordprocessing.Text(contentvalue); r.Append(t); r.Append(p1); sdt = new SdtContentRun(r); contentControls.First().SdtContentRun.RemoveAllChildren(); contentControls.First().SdtContentRun.InsertAt(sdt, 0);
var sdt = new SdtContentRun(); Run r = new Run(); DocumentFormat.OpenXml.Wordprocessing.Text t; t = new DocumentFormat.OpenXml.Wordprocessing.Text(contentvalue); r.Append(t); r.Append(p1); sdt = new SdtContentRun(r); contentControls.First().SdtContentRun.RemoveAllChildren(); contentControls.First().SdtContentRun.InsertAt(sdt, 0);
First, it looks like some significant chunks of your code are missing.
Second, could you clarify if the XML has the repeated value? Do the content controls have some other value initially? If you actually see different values in the XML, but Word is showing the same value for all, then it is a very different issue. Essentially, I am trying to understand if the problem is Word's reading of the XML or the XML generation.
Thanks for your reply
during assigning the value to contentcontrol [through XML] we had correct data, but when opening the word it shows duplicate.
we had correct data in xml but in word it shows duplicate[first content control value replace to all content control].
Now i tried to move the content control from table to outside table, then xml values applied correctly. again move back the content control to table ( same previous location) , this time also xml values applied correctly....
can u suggest .. what will be the problem.. any ideas?