I would like to modify a file in the bd SQL Server
I am designing a C# application that stores word files in a SQL Server database but I like to open the files from my datagridview and save changes coming from MS Word.
I would like to modify a file in the bd SQL Server
I am designing a C# application that stores word files in a SQL Server database but I like to open the files from my datagridview and save changes coming from MS Word.
1条答案
按热度按时间amrnrhlw1#
This is less an answer than it is an extended comment. First, we don't "do it for [you]... if possible reproduce the code etc.". We help you by answering questions about coding that you ask, preferably by you showing us your code and asking questions about that.
But, here's an attempt to answer what you are looking for. I'm assuming this is Windows Forms (there's a
winforms
tag you can use on your question, by the way). My assumption is based on your reference toDataGridView
.By the way, a SQL Server database doesn't store files. It can store blobs of stuff that would normally be in a file, but not files. In what you seem to be describing, it's likely going to be storing OpenXML data that would normally be in a
.docx
file.I'm guessing that you are trying to build a Windows Forms app that has a DataGridView (DGV). Each row of the grid will represent one of your database-resident "files". It will have some metadata (like the "filename") and a control (likely a button) that will act to open the "file" in Word.
To do this, you will need to copy the blob of file data out of your database row and create an actual (temporary) file somewhere, and then start Word, pointing it to your newly created file.
The .NET Framework provides you with two tools you can use at this point.
FileSystemWatcher
. You can point it at a file and you will be notified whenever that file is updated or deleted.What you want to do with this information is really up to you. After this, it is, as @siggemannen said in the comments, just a matter of figuring out what the parts of this are, and then writing code to implement those parts. Remember, if you have issues with your code, come back here, show us your code, and get answers.
Update:
You're begging me to write your software for you. That's not how this site works (and, I work for a living and don't have time to do your work). But, this should help.
When someone clicks the rows button:
Select the blob data for that row
Write it out to a temporary file (use the TEMP environment variable to find a good place - use a name that's not to obvious, but that ends in
.docx
)Use a FileSystemWatcher to monitor that file for changes
Use System.Diagnostics.Process (using the Shell) to start that document up, opening it in Word
Using the Process object that you got when you started up your document, and hook up an
Exited
event handler.Decide what you want to do with the events from the FileSystemWatcher and the Exited event. You could update the data in the database on every change, or simply monitor the file for changes and update it when Word exits. You likely want to delete the temporary file while the Exited event happens.
There you go.