Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert file to base64 function output

Public Function ConvertFileToBase64(ByVal fileName As String) As String

    Dim ReturnValue As String = ""

    If My.Computer.FileSystem.FileExists(fileName) Then
        Using BinaryFile As FileStream = New FileStream(fileName, FileMode.Open)
            Dim BinRead As BinaryReader = New BinaryReader(BinaryFile)
            Dim BinBytes As Byte() = BinRead.ReadBytes(CInt(BinaryFile.Length))
            ReturnValue = Convert.ToBase64String(BinBytes)
            BinaryFile.Close()
        End Using
    End If
    Return ReturnValue
End Function

The questions I want to ask:

  1. I want the output that is I want to convert a text file "C:\Users\user\Desktop\rats\test\test.txt" to base64
  2. I was unable to get any output when i converted "test.txt" to base64
  3. I use filename="textbox1.text" to add my "test.txt"
like image 832
user1412843 Avatar asked May 24 '12 14:05

user1412843


1 Answers

   Public Function ConvertFileToBase64(ByVal fileName As String) As String
        Return Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName))
    End Function
like image 190
user2086269 Avatar answered Oct 20 '22 05:10

user2086269