如何通过我的 C# Windows 应用程序从 sql server 打开 Office 文档,并在编辑完成后自动保存回数据库?
我们的应用程序是使用 .net 2.0 用 C# 编写的。 该应用程序跟踪我们的业务流程,用户可以附加办公文档作为附件以供参考。 他们经常编辑这些文档。 目前,他们必须将文件保存到硬盘,编辑并保存文件,然后重新附加到我们的应用程序以保存到数据库中(SQL 2005)。
我们的用户希望能够编辑文档并保存更改,而无需分离、编辑和重新附加。
我们可以通过编程方式启动 Office(word、excel 或 powerpoint)文档,但是我们如何判断文档何时关闭并自动将更新版本重新附加到数据库?
谢谢你的帮助。
乔
Our application is written in C# using .net 2.0. The application tracks our business process and users can attach office documents for reference as attachments. They frequently edit those documents. Currently, they have to save the file to their hard drive, edit and save the file, then re-attach to our application to save into database (SQL 2005).
Our users would like to be able to edit the document and save the changes without needing to detatch, edit, and re-attach.
We can programmatically launch the office (word, excel or powerpoint) document, but how can we tell when the document has closed and re-attach the updated version to the database automatically?
Thanks for any help.
Joe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能有一个指定的目录(例如Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)),您可以在其中保存当前编辑的文件,并放置一个FileSystemWatcher 来监视文件是否发生更改。
Diagnostics.Process 类还有一个“Exited”事件,该事件会在进程退出时通知您。
You may have a designated directory (e.g. Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) where you keep the files currently edited and put a FileSystemWatcher to watch whether the file changes.
The Diagnostics.Process class also has an "Exited" event that will notify you when the process, well, exited.
查看 MSDN 上的 SmartDocument 技术。 在您提到的三个生产力应用程序(Word、Excel、Powerpoint)中,前两个肯定(可能还有 Powerpoint)可以有右侧面板(您通常在其中看到样式、导航或任务),通过 VS 使用 SmartDocument 和Office 插件工具。
因此,您可以对面板进行编程,以便使用 Office 或 Excel(可能还有 PP - 还没有研究过)的用户可以从您的应用程序中选择要编辑的文档,进行编辑,然后保存/附加文档,全部来自Word界面。 右侧面板后面的编程将自动处理分离和重新附加文档,如果您愿意,还可以将文档保存到 SQLServer。
希望这可以帮助。
Look into SmartDocument technology at MSDN. Of the three productivity apps you mention (Word, Excel, Powerpoint) the first two for sure, and possibly Powerpoint, can have the right side panel -- where you usually see styles, navigation, or tasks -- programmed through VS using SmartDocument and Tools for Office plugins.
So, you can program the panel such that the user, working in Office or Excel (and possibly PP -- haven't looked into that) can select the document to be edited from your application, do the edits, and save/attach the document, all from the Word interface. The programming behind the right side panel will automagically take care of detaching, and reattaching the document, and can also save the document to SQLServer, if you like.
Hope this helps.
如果您使用 Process.Start 方法启动文件并将文件路径作为参数传递,则可以使用 WaitForExit() 方法在用户关闭文件时收到通知。
If you are launching the file by using Process.Start method and passing file path as a parameter, you can use the WaitForExit() method to be notified when the user has closed the file.