1

Is there any way where I can save a .ppt/.pptx file to a database, and then be able to retrieve it so I can edit it inside the application?

I know that I can do this for .doc/.docx files - storing them in rtf format and loading them into a RichTextBox with bold, italic, underline, and font controls, but is there anything like this for powerpoint files?

The closest solutions to what I want to achieve that I've found so far involve converting the ppt files to a video format, but that only allows me to view the powerpoint, not edit it; as well as using a WebBrowser control and using Navigate() to navigate between the slides, but once again this doesn't allow any editing.

Is there any solution to this?

Mighty Badaboom
  • 6,067
  • 5
  • 34
  • 51
cosmo
  • 751
  • 2
  • 14
  • 42
  • Why a database and not the file system? – Stephen Wilson Jul 17 '17 at 13:22
  • Your actual question is how you could edit PowerPoint files in a WPF application that you implemented? If that is the case I think there is no way to do it. Only if you would implement a parser and a presentation layer for PowerPoint files yourself – Romano Zumbé Jul 17 '17 at 13:24

1 Answers1

3

You could use OLE (Object Linking and Embedding) to host PowerPoint as an ActiveX control within WPF. Unfortunately WPF doesn't directly support OLE, but WinForms does. You would have to use a WindowsFormsHost to place a WinForms control, that does the OLE embedding in your WPF application.

This all starts to get very complex, very quickly, but it is possible. There is a Microsoft article on how to do it here. You would want to wrap PowerPoint instead of Windows Media Player instead, but the idea is the same. This will require that the end user has Power Point installed, and most likely, be the same version as the one the application was compiled against.

// Create the interop host control.
System.Windows.Forms.Integration.WindowsFormsHost host =
    new System.Windows.Forms.Integration.WindowsFormsHost();

// Create the ActiveX control.
AxWMPLib.AxWindowsMediaPlayer axWmp = new AxWMPLib.AxWindowsMediaPlayer();

// Assign the ActiveX control as the host control's child.
host.Child = axWmp;

// Add the interop host control to the Grid
// control's collection of child controls.
this.grid1.Children.Add(host);

Storing the file its self in the database is going to be the easy part.

copied from here:

public static void databaseFilePut(string varFilePath) {
    byte[] file;
    using (var stream = new FileStream(varFilePath, FileMode.Open, FileAccess.Read)) {
        using (var reader = new BinaryReader(stream)) {
            file = reader.ReadBytes((int) stream.Length);       
        }          
    }
    using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails))
    using (var sqlWrite = new SqlCommand("INSERT INTO Raporty (RaportPlik) Values(@File)", varConnection)) {
        sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file;
        sqlWrite.ExecuteNonQuery();
    }
}
Bradley Uffner
  • 16,641
  • 3
  • 39
  • 76