wordpress hit counter
Creating a PresentationML Document from a Database - OpenXML Developer - Blog - OpenXML Developer
Goodbye and Hello

OpenXmlDeveloper.org is Shutting Down

There is a time for all good things to come to an end, and the time has come to shut down OpenXmlDeveloper.org.

Screen-casts and blog posts: Content on OpenXmlDeveloper.org will be moving to EricWhite.com.

Forums: We are moving the forums to EricWhite.com and StackOverflow.com. Please do not post in the forums on OpenXmlDeveloper.org. Instead, please post in the forums at EricWhite.com or at StackOverflow.com.

Please see this blog post for more information about my plans moving forward.  Cheers, Eric

Creating a PresentationML Document from a Database

Creating a PresentationML Document from a Database

Rate This
  • Comments 8

Article by: Vijayeta.t of SONATA SOFTWARE LIMITED

This article explains how to fetch data from a database and use that data to create a PresentationML document.  Each slide in the presentation consists of a heading and a subtitle, and the data for these textboxes is retrieved from a table in database.

The attached sample application provides the user with a GUI, wherein the user has the option to choose the slide contents.


The user can select the database using the textbox provided, which displays the connection string.

The dropdown listbox contains all the topics for which the slides can be generated. On selection of a particular topic, the slide headings for that topic, and a brief data about the particular slide heading is displayed in the list view.

Among the slide headings displayed, user can select the titles required for the presentation document.


The presentation document is then generated, where slides would hold the selected headings and corresponding subtitles.

Initially the combo box drops down displaying the slides available. When a topic is selected,at the backend all the records corresponding the topic are fetched from the database, i.e. the table containing the Slide Titles and a brief description about the Title, and are mapped to the Listview. 

string selectstatement = "select Title,Description from mainTable " ;


SqlDataAdapter myAdpt = new SqlDataAdapter(selectstatement, conn);

DataSet ds=new DataSet ();

myAdpt.Fill(ds, "mainTable");

table = ds.Tables["mainTable"];


// Clear the ListView control




for (int i = 0; i < table.Rows.Count; i++)



        DataRow drow = table.Rows[i];

        listView1.GridLines = true;

        ListViewItem lvi = new ListViewItem(drow["Title"].ToString());

        lvi.SubItems .Add (drow ["Description"].ToString ());




On selection of the required titles, all the rows from the table containing the Titles and Subtitles are fetched and a comparison is done between the rows fetched and the items selected in the Listview, hence the slides are generated for the selected titles.

string selectstatement = "select Title,SubTitle from " + tableName;


SqlDataAdapter myAdpt = new SqlDataAdapter(selectstatement, conn);

DataSet ds = new DataSet();

myAdpt.Fill(ds, tableName);

table = ds.Tables[tableName];                                                    


for (int i = 0; i <table.Rows.Count; i++)



         DataRow drow = table.Rows[i];


         for (int j = 0; j <listView1.SelectedItems.Count; j++)



                    if (listView1.SelectedItems[j].ToString().Remove(0, 15).TrimEnd('}') == (drow[0].ToString()))



                            Heading.Add  ( drow[0].ToString());

                            SubTitle.Add  ( drow[1].ToString());



                            num +=1;




The files such as SlideX.xml that holds the contents of slides and presentation.xml that describes the relationship Id of each of the slides, are created programatically.

Additional xml files in the Presentation document are the standard files such as SlideLayouts, SlideMaster, NotesMaster and Themes.  Since these files are not created programatically,they are added along with the .exe file, which are then read and packaged to form the presentation package.  These files could also be created programatically as part of package.

The Application code and table structure required for the application to run is attached.

Attachment: pptDatabase.zip
  • Hi Vijayeta!

    How could we store PresentationML Document to SQL Server 2005 document?
    Would you pls give me some pointers in this regard?
  • Hi Lalit,
    Sorry for the delay.
    If your question is uploading the entire presentation document in the database,then you can visit the link,


    the language used is VB,but still this would give you an idea

    If you just want to store back only the data of the presentationML,into the tables in database,it's just the reverse procedure.

    You'll have to traverse through the xml file 'slideX.xml',search for the node with attribute 'ctrTitle',for titles and node with attributes,'subTitle' for the corresponding subtitles,and read their inner text.Both the titles and the subtitles can be updated in the corresponding tables.
    Do reply back,if I have not understood your question.

  • Thanks for reply!

    The link provided uses blob object for storing.
    I need something different than that like if there are images are used in the presentation,then that should be stored as image object and for rest of presentation part e.g. SlideX.xml as xml field in my database.
    I am trying to maintain the presentation not as a whole object but with the help of relationship.

    I need to add complete "pptx" document in the SQL server 2005 database and retrieve it back as "presentation" /package object.

    so for this i need to not only preserve the data of 'ctrlTitle' and other nodes but also all style and other shapes etc.
             Would you please has some pointers in this regards?

    Still,Thanks for your efforts!
  • Hi,
    Is it that you want to store each of the part of the presentation document,like styles.xml,slide1.xml,presentation.xml,and images and so on as separate parts in the database,and retrieve all the document parts into a single package to form the presentation document again?
    If yes,then you can programatically open the package,upload each of the part in a table(you must be aware of the xml  datatype in sql server 2005, to store xml files)
    To retrieve,you can maintain a directory structure,in your local disk and pack it back once you retrieve all the files.

    Note:Here you work with the package relations,which are constant and store the relationship files,such as 'presentation.xml.rels',as well in the table,and not a database relationship.

  • Yes,I realised that I have to store all of these docuement parts to get the presensentation back and I am aware of Xml datatype in sql2005.

    My problem again goes deeper as I can not fix up on the database schema,as I am not able to fix up on the "hirarchy of the folders that are generated under ppt folder" and "different datatypes that these folders containts".

    could you please guide me for schema designing?
    some useful pointers will aslo work.

    thanks again!
  • Hi Lalit,
    As i said before,you can iterate through the package(using System.IO.Packaging),read each of the file into the table,in database.
    For the differant kinds of files,such as,.png or .htm, you can have a predefined list of the extensions,and if the file type is not .xml,then you can store the files in the database in binary format.Also to maintain the same heirarchy,you can as well include a column in the table,which would hold the path.

    foreach (PackagePart part in package.GetParts())
              pathVal = part.Uri.ToString();
    You can insert the pathVal in the table

    "INSERT INTO upload VALUES ('" + partName + "', CONVERT(xml,'" + doc.InnerXml + "'),'" + pathVal + "')"

    doc is the corresponding xml file contents

    While retrieving,you can again follow the procedure of creating the part in the package,using the path retrieved from the table.

    Hope this helps.
  • Hi Vijayeta!

    Thanks a million for this post!
    I had just finished implementing this before your last post.As I realised what you tried to convey from the previous post.

    Thanks a lot again and yes,keep up the good work going.

    waiting for your next articles on OpenXML .
  • Hi Vijayeta

    I downloaded and tried out your sample code...
    the resulting pptx file can't be read by Powerpoint 2003 with Compatibility Pack; I already applied Office2007Converters.adm policy to that wasnt an issue. Still getting an error about "accessing file".
    Any thoughts on this?
    Many Thanks, Nate
Page 1 of 1 (8 items)