Currently I have a task that insert custom note to a particular slide of a ppt using openxml. from referencing this
link. I am trying to add note to a slide but I am getting the following Error.
Error Message :Only one instance of the type is allowed for this parent.
Stack Trace:
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.InitPart[T](T newPart, String contentType, String id)
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.InitPart[T](T newPart, String contentType)
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddNewPartInternal[T]()
at DocumentFormat.OpenXml.Packaging.OpenXmlPartContainer.AddNewPart[T]()
at AddNoteToPPT.Program.AddNote(String docName, Int32 index) in d:\Projects\Task\Project\AddNoteToPPT\AddNoteToPPT\Program.cs:line 45
Here is my working copy
NotesSlidePart notesSlidePart1 = slide.AddNewPart<NotesSlidePart>();
NotesSlide notesSlide = new NotesSlide(
new CommonSlideData(new ShapeTree(
new P.NonVisualGroupShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)1U, Name = "" },
new P.NonVisualGroupShapeDrawingProperties(),
new ApplicationNonVisualDrawingProperties()),
new GroupShapeProperties(new TransformGroup()),
new P.Shape(
new P.NonVisualShapeProperties(
new P.NonVisualDrawingProperties() { Id = (UInt32Value)2U, Name = "" },
new P.NonVisualShapeDrawingProperties(new ShapeLocks() { NoGrouping = true }),
new ApplicationNonVisualDrawingProperties(new PlaceholderShape())),
new P.ShapeProperties(),
new P.TextBody(
new BodyProperties(),
new ListStyle(),
new Paragraph(new EndParagraphRunProperties()))))),
new ColorMapOverride(new MasterColorMapping()));
notesSlidePart1.NotesSlide = notesSlide;
using this code I am able to get the content of existing Note.
slide.NotesSlidePart.SlidePart.NotesSlidePart.NotesSlide.InnerText