I use this function to convert file to bytes array:
Public Function ConvertToBytes(ByVal path As String) As Byte()
Dim _tempByte() As Byte = Nothing
If String.IsNullOrEmpty(path) = True Then
Throw New ArgumentNullException("File not exist", path )
Return Nothing
End If
Try
Dim _fileInfo As New IO.FileInfo(path )
Dim _NumBytes As Long = _fileInfo.Length
Dim _FStream As New IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read)
Dim _BinaryReader As New IO.BinaryReader(_FStream)
_tempByte = _BinaryReader.ReadBytes(Convert.ToInt32(_NumBytes))
_fileInfo = Nothing
_NumBytes = 0
_FStream.Close()
_FStream.Dispose()
_BinaryReader.Close()
Return _tempByte
Catch ex As Exception
Return Nothing
End Try
End Function
It's all working all right when file is not shared but when files are shared I go to exception from this code line:
Dim _FStream As New IO.FileStream(path, IO.FileMode.Open, IO.FileAccess.Read)
What is problem with my function?
Thanks!