Peter Poulsen
Peter Poulsen

Reputation: 542

How to use Word to edit documents in a database

This may be completely impossible, but I'll ask anyway :)

In our application we save all our data in a database (no surprises there). Among other thing we have some documents saved, and lets the user edit these documents using an in-build editor we have.

We would like to replace this with Microsoft Word (we don't have be backward compatible, so just forget about the existing documents).

Ideally I would like a functionality similar to OneDrive or SharePoint. The user finds the document in my application, opens in Word, and changes are automatically save back to where the document was opened from.

Having looked at Microsoft.Office.Interop.Word I'm able to open and edit Word files, but I need to save to the database (I think a stream would suffice. I think I'll be able to redirect that to the database). Anyone that knows of a way to open a stream instead?

I have also looked at DocumentFormat.OpenXml.Wordprocessing which seems to give me the handles to edit Word documents even from streams, but I would really like to open in the Word application, and not have to reimplement Word from scratch.

The application is written in C# with WPF if it matters :)

Yours /peter

Upvotes: 0

Views: 951

Answers (1)

Ondrej Tucny
Ondrej Tucny

Reputation: 27974

You have two options to go:

  • save the Word document to a temporary folder, launch Word from your app specifying the location as a command-line argument; once the document is closed (watch for the lock file Word creates), save it back to your back-end storage;
  • implement WebDAV or any other protocol Word supports for connecting to document management systems (such as SharePoint).

The second option leads to a rather large development effort and/or use of 3rd party libraries that may implement such functionality. Should you consider developing it yourself, I'd start from Microsoft's open specifications.

Upvotes: 1

Related Questions