C# 如何将ppt文件保存到WPF数据库并检索它们进行编辑?

C# 如何将ppt文件保存到WPF数据库并检索它们进行编辑?,c#,database,C#,Database,是否有任何方法可以将.ppt/.pptx文件保存到数据库中,然后能够检索该文件,以便在应用程序中对其进行编辑 我知道我可以为.doc/.docx文件执行此操作-以rtf格式存储它们,并将它们加载到带有粗体、斜体、下划线和字体控件的RichTextBox,但powerpoint文件是否有类似的操作 到目前为止,我找到的最接近我想要实现的目标的解决方案包括,但这只允许我查看powerpoint,而不允许我编辑它;以及使用WebBrowser控件和使用Navigate()在幻灯片之间导航,但这同样不允

是否有任何方法可以将.ppt/.pptx文件保存到数据库中,然后能够检索该文件,以便在应用程序中对其进行编辑

我知道我可以为.doc/.docx文件执行此操作-以rtf格式存储它们,并将它们加载到带有粗体、斜体、下划线和字体控件的
RichTextBox
,但powerpoint文件是否有类似的操作

到目前为止,我找到的最接近我想要实现的目标的解决方案包括,但这只允许我查看powerpoint,而不允许我编辑它;以及使用
WebBrowser
控件和使用
Navigate()
在幻灯片之间导航,但这同样不允许任何编辑

有什么解决方法吗?

您可以使用OLE(对象链接和嵌入)在WPF中作为ActiveX控件托管PowerPoint。不幸的是,WPF不直接支持OLE,但WinForms支持。您必须使用
WindowsFormsHost
来放置WinForms控件,该控件在WPF应用程序中嵌入OLE

这一切开始变得非常复杂,非常迅速,但这是可能的。有一篇微软的文章是关于如何做到这一点的。您可能希望包装PowerPoint而不是Windows Media Player,但想法是一样的。这将要求最终用户安装了Power Point,并且很可能与编译应用程序时使用的版本相同

// 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);
将文件本身存储在数据库中将是最简单的部分

抄袭自:


为什么是数据库而不是文件系统?您实际的问题是如何在您实现的WPF应用程序中编辑PowerPoint文件?如果是这样的话,我想没有办法。仅当您自己为PowerPoint文件实现解析器和演示层时
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();
    }
}