Unusual file monitor results
Im trying to return the path of a saved word document. So im monitoring the directory for saved changes.
If i save a document called sheet.docx i get these results. How come its not displaying just the full path and dcoument? C:\Documents and Settings\Owner\Desktop\New Folder\Sheet.docx as this is the entry i need
http://i.imgur.com/0jiF6.png
here is my code
vb Code:
Private Sub fswDocumentDirectoryMonitor_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles fswDocumentDirectoryMonitor.Changed
Debug_LogFileChanged(e.FullPath)
End Sub
''' <summary>
''' Logs that a file has changed in the debug log list view.
''' </summary>
''' <param name="pathToFile">The path to the file that was changed.</param>
''' <remarks>
''' Assumes pathToFile is not null.
''' </remarks>
Private Sub Debug_LogFileChanged(ByVal pathToFile As String)
Dim count As Integer = lbMonitorDebug.Items.Count + 1
Dim message As String = String.Format("{0}- {1} Changed {2}", count, DateTime.Now, pathToFile)
lbMonitorDebug.Items.Add(message)
End Sub
Private Sub fswDocumentDirectoryMonitor_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
Debug_LogFileCreated(e.FullPath)
ReturnCreatedFileAfterPrompting(e.FullPath)
End Sub
''' <summary>
''' Logs that a file was created in the debug list box.
''' </summary>
''' <param name="fullPath">The full path to the file.</param>
Private Sub Debug_LogFileCreated(ByVal fullPath As String)
Dim count As Integer = lbMonitorDebug.Items.Count + 1
Dim message As String = String.Format("{0}- {1} Created {2}", count, DateTime.Now, fullPath)
lbMonitorDebug.Items.Add(message)
End Sub
Private Sub ReturnCreatedFileAfterPrompting(ByVal filePath As String)
Dim createdFile As New System.IO.FileInfo(filePath)
Select Case createdFile.Extension.ToLower()
' TODO: [AW] Magic list
Case ".doc", ".docx",
MessageBox.Show(createdFile.ToString)
End Select
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
fswDocumentDirectoryMonitor.IncludeSubdirectories = True
Catch ex As Exception
' TODO: [AW] Swallows all exceptions
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
''' <summary>
''' Toggles the state of the file system watcher.
''' </summary>
Private Sub StartMonitorState()
Try
If fswDocumentDirectoryMonitor.Path = "" Then
Dim message As String = "Please choose a directory to monitor"
MessageBox.Show(message)
Exit Sub
End If
fswDocumentDirectoryMonitor.EnableRaisingEvents = True
Catch ex As Exception
' TODO: Swallows all exceptions
' TODO: What errors are expected?
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Re: Unusual file monitor results
Re: Unusual file monitor results
Word does not just do a straight forward creation of a single file when you save a document. When you open a Word document it actually creates a temp file and write any changes you make to that, until you click Save and thats when it updates the original file. I presume when you create a new document it does a similar thing and creates some temp files then just renames one of them to the actual name of the document. If you are only monitoring for Created events then try monitoring LastModified as well and see what you get
Re: Unusual file monitor results
Quote:
Originally Posted by
chris128
Word does not just do a straight forward creation of a single file when you save a document. When you open a Word document it actually creates a temp file and write any changes you make to that, until you click Save and thats when it updates the original file. I presume when you create a new document it does a similar thing and creates some temp files then just renames one of them to the actual name of the document. If you are only monitoring for Created events then try monitoring LastModified as well and see what you get
Ok, so what do you think the best way is to detect 2 newly created files?
I use vb to create 2 word files and then save them manually.
I was going to use a file monitor to get these 2 newly saved files path. Would make it quicker then manual;ly browsing for these files to email
any suggestions?
Re: Unusual file monitor results
Why not just use VB to save them as well and then you already know where they are saved to?
Re: Unusual file monitor results
Quote:
Originally Posted by
chris128
Why not just use VB to save them as well and then you already know where they are saved to?
But how could vb know what i called the file and and the directory since im saving the file out of vb ??? Since its a word document ..... even though i built it in vb?