private void DeleteSlide(int index)
        {
            //TODO: try-catch
            PPT.Application   app  = new PPT.Application();
            PPT.Presentations pres = app.Presentations;

            PPT.Presentation pptx = pres.Open(LibraryFile.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

            PPT.Slides slides = pptx.Slides;
            PPT.Slide  slide  = slides[index];

            slide.Delete();

            pptx.Save();
            pptx.Close();

            slide.ReleaseCOM();
            slide = null;

            slides.ReleaseCOM();
            slides = null;

            pptx.ReleaseCOM();
            pptx = null;

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;
        }
Example #2
0
        /// <summary>
        /// Opens Presentation and selects slide
        /// </summary>
        /// <param name="path"></param>
        /// <param name="slideIndex"></param>
        private void OpenPresentation(string path, int slideIndex = 1)
        {
            PPT.Application   ppt             = null;
            PPT.Presentations pres            = null;
            PPT.Presentation  pptPresentation = null;

            try
            {
                ppt  = new PPT.Application();
                pres = ppt.Presentations;

                //TODO: Check if file is already opned
                pptPresentation = pres.Open(path);
                pptPresentation.Slides[slideIndex].Select();
            }
            catch (Exception)
            {
            }
            finally
            {
                pptPresentation.ReleaseCOM();
                pptPresentation = null;

                pres.ReleaseCOM();
                pres = null;

                ppt.ReleaseCOM();
                ppt = null;
            }
        }
        dynamic GetAddin()
        {
            PPT.Application ppt = new PPT.Application();

            COMAddIn mg = null;

            foreach (COMAddIn addin in ppt.COMAddIns)
            {
                if (addin.ProgId == "AddInID")
                {
                    mg = addin;
                    break;
                }
            }

            dynamic mgAddin = mg?.Object;

            mg.ReleaseCOM();
            mg = null;

            ppt.ReleaseCOM();
            ppt = null;

            return(mgAddin);
        }
Example #4
0
        public List <IFileItem> AppendShapes(List <PPT.Shape> srcShapes)
        {
            PPT.Application   ppt             = null;
            PPT.Presentations pres            = null;
            PPT.Presentation  pptPresentation = null;
            try
            {
                ppt  = new PPT.Application();
                pres = ppt.Presentations;

                pptPresentation = pres.Open(FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);

                PPT.DocumentWindow wnd = pptPresentation.Windows[1];
                //wnd.Height = 200;
                //wnd.Top = -200;
                wnd.WindowState = PPT.PpWindowState.ppWindowMinimized;
                wnd             = null;

                PPT.Slides gSlides    = pptPresentation.Slides;
                int        startIndex = gSlides.Count + 1;
                int        count      = 0;
                foreach (PPT.Shape shape in srcShapes)
                {
                    PPT.Slide slide = gSlides.Add(startIndex + count++, PPT.PpSlideLayout.ppLayoutBlank);
                    shape.Copy();
                    slide.Shapes.Paste();
                    slide.Tags.Add(ShapeTag.Tag, ShapeTag.Value);

                    slide.ReleaseCOM();
                    slide = null;
                }
                List <IFileItem> newItems = new List <IFileItem>();
                newItems = fileIndex.UpdateIndex(pptPresentation, startIndex);

                return(newItems);
            }
            finally
            {
                if (pptPresentation != null)
                {
                    pptPresentation.Save();
                    pptPresentation.Close();
                }
                pptPresentation.ReleaseCOM();
                pptPresentation = null;

                pres.ReleaseCOM();
                pres = null;

                ppt.ReleaseCOM();
                ppt = null;
            }
        }
        /// <summary>
        /// Scans pptx file and creates Index
        /// </summary>
        public void CreateIndex()
        {
            items.Clear();

            DeleteIndexFile();
            CreateIndexFile();

            PPT.Application   app          = null;
            PPT.Presentations preentations = null;
            PPT.Presentation  pptx         = null;
            try
            {
                app          = new PPT.Application();
                preentations = app.Presentations;
                pptx         = preentations.Open(LibraryFile.FullPath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
//                PPT.Slides gSlides = pptx.Slides;

                UpdateIndex(pptx, 1);
            }
            catch (Exception ex)
            {
                DeleteIndexFile();
                throw ex;
            }
            finally
            {
                pptx?.Close();
                pptx.ReleaseCOM();
                pptx = null;

                preentations.ReleaseCOM();
                preentations = null;

                app.ReleaseCOM();
                app = null;
            }
        }
Example #6
0
        protected void AddSelectedShapes(IFile libraryFile)
        {
            PPT.Application    ppt = null;
            PPT.Presentation   pr  = null;
            PPT.DocumentWindow aw  = null;
            PPT.Selection      sel = null;

            try
            {
                timerCheckForUpdates.Enabled = false;

                ppt = new PPT.Application();
                pr  = ppt.ActivePresentation;

                if (pr.FullName == libraryFile.FullPath)
                {
                    MessageBox.Show("You can't add slides to the same presentation");
                    return;
                }

                aw  = ppt.ActiveWindow;
                sel = aw.Selection;
                List <PPT.Shape> shapesToAdd = new List <PPT.Shape>();

                if (sel.Type == PPT.PpSelectionType.ppSelectionShapes)
                {
                    foreach (PPT.Shape slide in sel.ShapeRange)
                    {
                        shapesToAdd.Add(slide);
                    }
                }
                else
                {
                    shapesToAdd.Add(aw.View.Slide as PPT.Shape);
                }

                if (shapesToAdd.Count > 0)
                {
                    libraryFile.AppendShapes(shapesToAdd);
                    uxImagesView.DataSource = LibraryData.GetAllItems().ToList();
                    Filter();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                sel.ReleaseCOM();
                sel = null;

                pr.ReleaseCOM();
                pr = null;

                aw.ReleaseCOM();
                aw = null;

                ppt.ReleaseCOM();
                ppt = null;

                timerCheckForUpdates.Enabled = !needsUpdate;
            }
        }
Example #7
0
        private void Publish(IGroup group)
        {
            PPT.Application  app  = app = new PPT.Application();
            PPT.Presentation pres = app.ActivePresentation;

            string fileName = Path.GetFileName(pres.FullName);

            if (!Path.HasExtension(fileName))
            {
                fileName = Path.ChangeExtension(fileName, "pptx");
            }

            if (group.ContainsFile(fileName))
            {
                if (group.FullPath == Path.GetDirectoryName(pres.FullName))
                {
                    MessageBox.Show("You can't publish file in the folder where it is already located.");
                    return;
                }

                DialogResult res = MessageBox.Show("File with the same name exists. Replace?", "Slides Gallery",
                                                   MessageBoxButtons.OKCancel);
                if (res == System.Windows.Forms.DialogResult.Cancel)
                {
                    return;
                }
                if (res == System.Windows.Forms.DialogResult.No)
                {
                    //TODO: Get new name?
                    return;
                }
                else
                {
                }
            }


            group.DeleteFile(fileName);

            string newFilePath = Path.Combine(group.FullPath, Path.GetFileName(fileName));

            pres.SaveCopyAs(newFilePath);


            IFile file = group.AddFile(fileName);

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;

            if (file != null)
            {
                if (treeBuilder == null)
                {
                    LoadLibraryData();
                }

                treeBuilder.AddFile(file);
                ReloadDataSource();
            }
        }
Example #8
0
        private void InsertItem(IFileItem item)
        {
            if (item == null)
            {
                return;
            }

            PPT.Application   app  = new PPT.Application();
            PPT.Presentations pres = app.Presentations;

            PPT.Presentation pptx   = pres.Open(item.File.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            PPT.Slides       slides = pptx.Slides;
            PPT.Slide        slide  = slides[item.Index];

            if (item.Type == ItemType.Slide)
            {
                slide.Copy();
            }
            else
            {
                PPT.Shapes shapes = slide.Shapes;
                PPT.Shape  shape  = shapes[1];

                shape.Copy();

                shapes.ReleaseCOM();
                shapes = null;
                shape.ReleaseCOM();
                shape = null;
            }

            PPT.Presentation dstpptx = app.ActivePresentation;

            PPT.DocumentWindow wnd  = app.ActiveWindow;
            PPT.View           view = wnd.View;

            //TODO: Check if there is no selection (selection between slides)
            PPT.Slides dstSlides = dstpptx.Slides;
            PPT.Slide  dstSlide  = null;

            dstSlide = view.Slide as PPT.Slide;
            int ix = dstSlide.SlideIndex + 1;

            if (item.Type == ItemType.Slide)
            {
                dstSlide.Copy();

                var r = dstSlides.Paste(); //TODO: dstSlides.Paste(ix) Hangs here
                var s = r[1];

                s.MoveTo(ix);

                s.ReleaseCOM();
                s = null;

                r.ReleaseCOM();
                r = null;
            }
            else
            {
                view.Paste();
            }

            dstSlide.ReleaseCOM();
            dstSlide = null;

            wnd.ReleaseCOM();
            wnd = null;

            view.ReleaseCOM();
            view = null;

            dstpptx.ReleaseCOM();
            dstpptx = null;


            slide.ReleaseCOM();
            slide = null;

            slides.ReleaseCOM();
            slides = null;

            pptx.Close();
            pptx.ReleaseCOM();
            pptx = null;

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;

            dstSlides.ReleaseCOM();
            dstSlides = null;
        }
Example #9
0
        public List <IFileItem> AppendSlides(List <PPT.Slide> srcSlides)
        {
            PPT.Application   ppt             = null;
            PPT.Presentations pres            = null;
            PPT.Presentation  pptPresentation = null;
            try
            {
                ppt  = new PPT.Application();
                pres = ppt.Presentations;

                pptPresentation = pres.Open(FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);

                PPT.DocumentWindow wnd = pptPresentation.Windows[1];
                //wnd.Height = 200;
                //wnd.Top = -200;
                wnd.WindowState = PPT.PpWindowState.ppWindowMinimized;
                wnd             = null;

                #region Alt. slower approach by copy ppt and insert slides from file
                //Copy
                //string tempFile = @"c:\WRK\Temp.pptx";
                //ppt.ActivePresentation.SaveCopyAs(tempFile, PPT.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
                //PPT.Presentation tempPPT = ppt.Presentations.Open(tempFile,MsoTriState.msoFalse,MsoTriState.msoFalse, MsoTriState.msoFalse);

                //List<string> slideNames = slides.Select(slide => slide.Name).ToList();
                //var v = from PPT.Slide sl in tempPPT.Slides where !slideNames.Contains(sl.Name) select sl;
                //foreach(PPT.Slide s in v)
                //{
                //    s.Delete();
                //}
                //tempPPT.Save();
                //tempPPT.Close();
                //gallery.Slides.InsertFromFile(tempFile, gallery.Slides.Count);
                #endregion

                PPT.Slides gSlides    = pptPresentation.Slides;
                int        startIndex = gSlides.Count + 1;
                foreach (PPT.Slide slide in srcSlides)
                {
                    slide.Copy();
                    gSlides.Paste();
                }
                List <IFileItem> newItems = new List <IFileItem>();
                newItems = fileIndex.UpdateIndex(pptPresentation, startIndex);

                return(newItems);
            }
            finally
            {
                if (pptPresentation != null)
                {
                    pptPresentation.Save();
                    pptPresentation.Close();
                }
                pptPresentation.ReleaseCOM();
                pptPresentation = null;

                pres.ReleaseCOM();
                pres = null;

                ppt.ReleaseCOM();
                ppt = null;
            }
        }