Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have some code here for FileSystemWatcher1_Changed.


Private Sub FileSystemWatcher1_Changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
        Dim path As FileStream = Nothing
        Try

            path = File.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None)
            path.Close()
        Catch ex As Exception

            Dim sample As String
            sample = md5_hash(path)


            Using f As System.IO.FileStream = System.IO.File.OpenRead("viruslist.txt")
                Using s As System.IO.StreamReader = New System.IO.StreamReader(f)
                    While Not s.EndOfStream
                        Dim line As String = s.ReadLine

                        If (line = sample) Then
                            Detect.ShowDialog()
                        End If
                    End While
                End Using
            End Using
        End Try
    End Sub



In line
sample = md5_hash(path)
, 'path' is saying that Value type of 'FileStream' cannot be converted to 'String'.


Is there any way of fixing this?

What I have tried:

Researching this problem.


Declaring 'path' as an array (for some reason I thought it might do something.)
Posted
Updated 4-Jun-18 20:21pm

FileSystemWatcher1_Changed provides you with a path: the parameter e is of type FileSystemEventArgs which has a property FullPath.

So:

path = e.FullPath
 
Share this answer
 
Go back to your previous question: Is there a way to assign a file path to a variable when its opened without using openfiledialog?[^] and read the answer.
Then look at your code, and start thinking. At the moment, you are guessing what to do - and that isn't a viable development strategy.
Look at the code you show us! It won't even compile for so many reasons that it's getting silly :laugh:

And what on earth makes you assume that - even if that code did miraculously start working - all files that change will contain text-based data (i.e. data that will fit in a string)? Very little data on a computer is text: only the human readable stuff. So your MD5 (which is not recommended for new projects anyway and hasn't been for half a dozen years) method should not expect a string, it should expect an array of bytes.

Seriously: stop guessing; start thinking. This isn't difficult code, but you are doing your damnedest to make it as complicated as possible!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900