I have files that have a unc path with a filename entered into the comments of the file and I would like to be able to simply read the comments of a given file and if the comments contain a legit unc path then move the file to the location given.
When I run this code...
Public Sub remigrate(ByVal source As String)
Dim returnPath As String
returnPath = OrigPath(source.ToString)
If returnPath.ToString.Contains("\\") = True Then
System.IO.File.Move(source.ToString, returnPath)
End If
End Sub
Private Function OrigPath(ByVal file As String) As String
Dim FileProps As New DSOFile.OleDocumentProperties
FileProps.Open(file, True)
Dim oSumProps As DSOFile.SummaryProperties
oSumProps = FileProps.SummaryProperties
If System.String.IsNullOrEmpty(oSumProps.Comments) = True Then
Return "0"
Else
Return oSumProps.Comments.ToString
End If
oSumProps = Nothing
FileProps.Close(False)
FileProps = Nothing
End Function
I always get this error message.
Unhandled Exception: System.IO.IOException: The process cannot access the file because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIOError()
at System.IO.File.Move(String sourceFileName, String destFileName)
How can I get the OrigPath Function to release the lock it has on the source file?