How to put ppowerpoint presentations in website using with c#? can u please tell me anyone.

rajvinder.tomer commented: HOW CAN WE LARN ASP.NET COPLETELY +0

Recommended Answers

All 6 Replies

How to put ppowerpoint presentations in website using with c#? can u please tell me anyone.

Public Shared Sub CreatePPT(ByVal pptOutputFile As String)
        Dim chartImageFileName As String
        Dim chartImage As System.Drawing.Image

        Dim powerPointApp As New Microsoft.Office.Interop.PowerPoint.Application()
        Dim ppt As Microsoft.Office.Interop.PowerPoint.Presentation = powerPointApp.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue)
                chartImageFileName = "D:\cm1.gif"

                chartImage = System.Drawing.Image.FromFile(chartImageFileName)

                'init PowerPoint 

                'create a new slide 
                Dim slide As Microsoft.Office.Interop.PowerPoint.Slide = ppt.Slides.Add(1, Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutBlank)

                ' see if chart image could not fit slide frame 
                Dim actualChartImageWidth As Single = IIf((chartImage.Width > slide.Master.Width), slide.Master.Width, chartImage.Width)
                Dim actualChartImageHeight As Single = IIf((chartImage.Height > slide.Master.Height), slide.Master.Height, chartImage.Height)

                'the center position of the slide 
                Dim docXCenter As Single = slide.Master.Width / 2
                Dim docYCenter As Single = slide.Master.Height / 2

                'the center position of the chart image 
                Dim picXCenter As Single = actualChartImageWidth / 2
                Dim picYCenter As Single = actualChartImageHeight / 2

                'calculate how much to move the chart image to center it 
                Dim moveX As Single = docXCenter - picXCenter

                If moveX < 0 Then
                    moveX = 0
                End If

                Dim moveY As Single = docYCenter - picYCenter

                If moveY < 0 Then
                    moveY = 0
                End If

                'add a picturebox to the slide 
                slide.Shapes.AddPicture(chartImageFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, moveX, moveY, actualChartImageWidth, actualChartImageHeight)
                slide = Nothing


            'save the powerpoint slide 
            ppt.SaveAs(pptOutputFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse)

            'clean up Powerpoint 

            ppt = Nothing
            powerPointApp = Nothing


            'make sure the PowerPoint process is killed after use 
            Dim processes As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("POWERPNT")
            If processes.Length = 1 Then
            End If
        Catch ex As Exception
            '  Throw New ChartPPTExportException("PPTException: " + ex.Message, ex)
        End Try
    End Sub

Thanks for great VB post on Powerpoint COM Interop. Here's my similar C# conversion:

using System;
using System.Windows;
using Microsoft.Office.Interop.PowerPoint;

namespace ForeshareAutomatedPresentation
    public partial class MainWindow : Window
        public MainWindow()

        private void Window_Loaded(object sender, RoutedEventArgs e)

        private void CreatePowerPointPresentation(string strOutputFile)
            string strChartImageFileName;
            System.Drawing.Image imgChartImage;
            Microsoft.Office.Interop.PowerPoint.Application oPowerPointApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation oPpt = oPowerPointApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
                strChartImageFileName = @"c:\data\qv.png";
                imgChartImage = System.Drawing.Image.FromFile(strChartImageFileName);

                //define custom layout
                CustomLayout oCl = oPpt.SlideMaster.CustomLayouts[1];

                //create slide
                Microsoft.Office.Interop.PowerPoint.Slide oSlide = oPpt.Slides.AddSlide(1, oCl);

                //is image small enough for slide?
                Single sglActualChartImageWidth = imgChartImage.Width > oPpt.SlideMaster.Width ? oPpt.SlideMaster.Width : imgChartImage.Width;
                Single sglActualChartImageHeight = imgChartImage.Height > oPpt.SlideMaster.Height ? oPpt.SlideMaster.Height : imgChartImage.Height;

                //centre pos of slide:

                Single sglDocXCentre = oPpt.SlideMaster.Width / 2;
                Single sglDocYCentre = oPpt.SlideMaster.Height / 2;

                //centre pos of the image:

                Single sglPicXCentre = sglActualChartImageWidth / 2;
                Single sglPicYCentre = sglActualChartImageHeight / 2;

                //how much to move the image to centre it?

                Single sglMoveX = sglDocXCentre - sglPicXCentre;
                Single sglMoveY = sglDocYCentre - sglPicYCentre;

                if (sglMoveX < 0) sglMoveX = 0;
                if (sglMoveY < 0) sglMoveY = 0;

                //add a picturebox to slide:

                oSlide.Shapes.AddPicture(strChartImageFileName, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, sglMoveX, sglMoveY, sglActualChartImageWidth, sglActualChartImageHeight);

                oSlide = null;

                oPpt.SaveAs(strOutputFile, PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoFalse);

                //clean up

                oPpt = null;
                System.Diagnostics.Process[] prc = System.Diagnostics.Process.GetProcessesByName("POWERPNT");
                if (prc.Length == 1)
            catch (Exception ex)

Jarrod Krige

Please can you explain me how it works?


Iam new to I Don't Know the how to uses of Slide Show Extender and image sliding .Please suggeste me........
Thanks in Adevance

hi ,

It is possible to integrate a .NET PowerPoint component into your Web appliction so that you can process PPT slide on website, this way ,you can save a lot time comparing to deploying Microsoft.Office.Interop.PowerPoint in your project.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.