I'm trying to change the properties of a word programmatically.
To do this I created a windows service from. Net.
I have this code
Sub ModificarPropiedadesWord() Dim filePaths As String() filePaths = Directory.GetFiles("C:\Words\") If filePaths.Length > 0 Then For Each fi As String In filePaths If Wapp Is Nothing Then Wapp = New Word.Application End If If docWord Is Nothing Then docWord = New Word.Document Else End If Dim info As New FileInfo(fi) Try docWord = Wapp.Documents.Open("C:\Words\" + Path.GetFileNameWithoutExtension(info.Name) + ".doc") Dim _BuiltInProperties As Object = docWord.BuiltInDocumentProperties If Not _BuiltInProperties Is Nothing Then _BuiltInProperties("Author").Value = "TEST" _BuiltInProperties("Subject").Value = "TEST" _BuiltInProperties("Manager").Value = "TEST" _BuiltInProperties("Company").Value = "TEST" _BuiltInProperties("Category").Value = "TEST" _BuiltInProperties("Keywords").Value = "TEST" _BuiltInProperties("Comments").Value = ""TEST" docWord.Saved = False docWord.Save() End If If Not docWord Is Nothing Then docWord.Close() docWord = Nothing End If If Not Wapp Is Nothing Then Wapp.Quit() Wapp = Nothing End If Catch ex As Exception Dim w As New IO.StreamWriter("C:\logDAL.txt", True) w.WriteLine("ExcepTion modify properties" & ex.ToString() & " " & DateAndTime.Now.ToString()) w.Close() End Try Next End If End Sub
works well while the service runs continuously, but errors ifinterrupted.
I get the classic error
"The process can not access the file is being because is used by another process"
because in the process keeps running background also generates temporary files and others like show in the image
sow mi question is , how i can handled this bugs=???