从 C# 资源中提取并打开 PPT
我想在 PowerPoint 查看器中查看演示文稿,ppt 文件位于资源中。所以问题是我如何访问它并在 PowerPoint 查看器中查看。
这是示例代码
Process.Start(@"C:\Program Files\Microsoft Office\Office12\PPTVIEW.exe",**@"e:\presentation.ppt")**;
如何用资源中包含的 ppt 替换此路径?
I want to view presentation in PowerPoint viewer, ppt file is in a resources. so the problem is that how can i access it and view in PowerPoint viewer.
Here is sample code
Process.Start(@"C:\Program Files\Microsoft Office\Office12\PPTVIEW.exe",**@"e:\presentation.ppt")**;
How can i replace this path by ppt containing in resources?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,你所要求的是一个常见的模式,这里有一些相关的问题和答案。
基本上,您通常要做的事情如下:
因此,您首先提取 PPT 文件(实际上,它是 PPT 文件并不重要,可以是任何文件或字节 blob)。
然后使用
Process.Start()
。您无需指定 Powerpoint 可执行文件的路径,因为 PPT 应该是通过 PowerPoint 或 PowerPoint Viewer 注册的文件扩展名。如果您已安装两者,您可能仍需要提供相关可执行文件的路径,以防止启动错误的应用程序。确保您没有对路径进行硬编码,而是尝试从注册表中检索它(或类似的,我没有检查,因为现在变得太具体了)。注意:我遗漏了一些您可能想要在实际应用程序中添加的错误处理。
Actually, what you ask for is a common pattern and there are some related questions and answers here on SO.
Basically what you do in general is the following:
So, you first extract the PPT file (actually it doesn't really matter that it is a PPT file, could by any file or byte blob for that matter).
Then you open it using
Process.Start()
. You don't need to specify the path to the Powerpoint executable, as PPT should be a registered file extension with either PowerPoint or the PowerPoint Viewer. If you have both installed, you may still want to provide the path to the relevant executable to prevent launching the wrong application. Make sure that you don't hardcode the path though, but try to retrieve it from the registry (or similar, I haven't checked because that gets too specific now).Note: I left out quite some error handling that you might want to add in a real application.