How do we get the complete file path using FileSystemWatcher ?

ipjyo used Ask the Experts™
I am trying to use FileSystemWatcher to find if a file is present or not. Based on this it will raise an event to do some processing.
my code is as shown in the attached.
my question is, how do I get the complete file path including the file name?
currently when I try to see the value of
it is holding only the directory path. In my example, it has only upto C:\Sample Files.
But I need to have the complete file path so it can pass the filename to another method where the actual processing will be done.
Thank you for any help!
Private Sub IntializeFileSystemWatcher()
            'Create File System Watcher for DAT files
            fsWatcher = New System.IO.FileSystemWatcher("C:\Sample Files", "*.DAT")
            ' Add event handlers for new files and change of existing files.
            'fsWatcher.Changed += new FileSystemEventHandler(OnFileChanged)
            AddHandler fsWatcher.Created, AddressOf OnFileCreated
            ' Begin watching.
            fsWatcher.EnableRaisingEvents = True
        End Sub
        Private Sub OnFileCreated(ByVal source As Object, ByVal e As FileSystemEventArgs)
            Dim ConvertXml As Translator
            ConvertXml = New Translator()
            Dim XmlDoc As New XmlDocument
                XmlDoc = ConvertXml.Prepare(fsWatcher.Path.ToString())
                '  MessageBox.Show("XML successful")
            Catch ex As Exception
                System.Windows.Forms.MessageBox.Show(ex.Message.ToString(), "", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question, System.Windows.Forms.MessageBoxDefaultButton.Button1, System.Windows.Forms.MessageBoxOptions.ServiceNotification)
            End Try
        End Sub

Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Once you get the directory you have to loop through each files and get there names.

Here is a sample file system watcher which does what you want
In my projects I use System.IO.File.Exists(filename) to check if a file exists. The whole IO.File structure specifically serves the purpose of handling files. You can check out also IO.File.FileInfo class, which serves to store all sorts of information on files
The FileSystemEventArgs in the event handler specifies what file was affected.
In the OnFileCreated eventhandler, use:


to get the filename.


Thank you all for the suggestions.
e.fullpath worked for me.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial