Ejemplo n.º 1
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();
            }
        }