Question

Im beggineer in programming and i'm trying to delete the master slide usign the c# but it always throws an exception "Specified cast is not valid" Is there any way to delete the master slide or shapes on the master slide .. please suggest.

 for (int i = 1; i <= SlideCount; i++)
           {
                int j=i;
                slide = Slides[i];

                //iterate over all the shapes of notespage of given slide to find the notespage's shape which has text.
                 for (int k = 1; k <= slide.NotesPage.Shapes.Count; k++)
                 {
                      var noteShape = slide.NotesPage.Shapes[k];

                     //check if the selected notespage has text or not
                     if (noteShape.Type ==MsoShapeType.msoPlaceholder)
                     {
                         if (noteShape.PlaceholderFormat.Type ==PpPlaceholderType.ppPlaceholderBody)
                         {
                             if (noteShape.HasTextFrame ==MsoTriState.msoTrue)
                             {
                                 if (noteShape.TextFrame2.HasText ==MsoTriState.msoTrue)
                                 {

                                        //create a new slide 
                                        newslide = tempslides.AddSlide(++j, customLayout);

                                        // set the  title of newslide as the text of notepage of previous slide.
                                        newslide.Shapes.Title.TextFrame.TextRange.Text = noteShape.TextFrame.TextRange.Text;

                                        //delete the notepage text; 
                                        noteShape.TextFrame.TextRange.Delete();

                                        //delete footer from slide. 
                                        //if (newslide.HeadersFooters.Footer.Visible == MsoTriState.msoTrue)
                                        //    newslide.HeadersFooters.Footer.Text = string.Empty;
                                        //newslide.HeadersFooters.DateAndTime.Text = string.Empty;
                                        //newslide.HeadersFooters.SlideNumber.Text = string.Empty;
                                        newslide.HeadersFooters.Clear();
                                        newslide.Master.Delete();




                                        //jump to next slide  
                                        i++;

                                        //increase the slide count becoz one slide has been added.
                                        SlideCount = tempslides.Count;
                                 }

                              }

                         }

                     }

                 }
             }
Was it helpful?

Solution

You can't delete a master or layout that any slides are based on. Why do you want to delete the master slide?

To delete the shapes:

newslide.Master.Shapes.Range.Delete

That will delete the shapes from the slide master, but not the layout that the slide is based on, so it may not be exactly what you need.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top