Click here to Skip to main content
15,888,031 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have generated the word document using Interop Word.Now I'm unable to remove the controls from the generated word document.

Please find my code below.

C#
Word.Application myWordApp = new Word.Application();
object missing = System.Reflection.Missing.Value;
object oTemplate = strWordDoc;            
Word.Document document = myWordApp.Documents.Add(ref oTemplate, ref missing, ref missing,  ref missing);

foreach (Word.ContentControl contentControl in document.ContentControls)
{
  contentControl.SetPlaceholderText(null, null,"Trial");              
}
myWordApp.ActiveWindow.ActivePane.View.Type = Word.WdViewType.wdPrintView;
myWordApp.Visible = true;
object index = 1;
document.Windows.get_Item(ref index).View.Type = Word.WdViewType.wdPrintView;
Posted
Updated 26-Jun-13 1:42am
v6
Comments
ZurdoDev 24-Jun-13 12:55pm    
Where are you stuck?
Nelek 24-Jun-13 14:11pm    
naveu2007 24-Jun-13 15:04pm    
I hardly find any method to delete the controls from the word template which has been edited progrmatically using the interop word.I tried finding the controls and replaced them with the desired text but not able to remove the content contros from it.
Sunasara Imdadhusen 25-Jun-13 7:09am    
please do not post your code in comment box, use update question option
naveu2007 25-Jun-13 9:45am    
As Im new here donno where to update...
Thanks for the info

1 solution

Hi all resolved my issue :):) thanks for the support..


Just replaced the code as below

C#
foreach (Word.ContentControl contentControl in document.ContentControls)
{
  contentControl.Range.Text="Trial";
  contentControl.Delete(false);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900