Hi. We're trying to integrate better with Word using the Microsoft.Office.Interop dlls and running into issues.
The problem is simple.
1. User picks a file to open from the server. Server ships the file over and displays it in the client.
2. User makes changes to file in the client
3. User hits "Save Button"
What I'd like to happen at this point is to call the WordDocument.Save routine on the client and then once that is finished send a copy of the saved version back over to the server to keep the files in sync. The problem is that just having the file open in word blocks read access to the file!
If I'm not running code and just in Windows I seem to have read access as I can open a file in word and then copy/paste copies of the file all day long in windows explorer.... but if I'm in code the file is locked. What am I doing wrong?
FYI Im running office 2007
Here is a little code to demonstrate.. as you can see all I do is open a word file and then try to create a read only stream from it and it bombs.
Public Sub Test()
Dim FilePath As String = "C:\Change to Your Path\Test Doc.docx"
' Create a new instance of word and open some document in it
Dim WordInstance As New Microsoft.Office.Interop.Word.Application
Dim Document As Microsoft.Office.Interop.Word.Document = WordInstance.Documents.Open(FilePath)
' Now try to create a readonly stream (to send a copy of our
' changes back to the server)
Dim fStream As FileStream = Nothing
fStream = New FileStream(Me._FilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message)
If fStream IsNot Nothing Then
fStream = Nothing