' FileToStr() VFP equivalent ' expC1 File name Public Function FileToStr(ByVal tcFileName As String) As String Dim loFile As IO.StreamReader Dim lcString As String Try loFile = New IO.StreamReader(tcFileName, True) lcString = loFile.ReadToEnd() loFile.Close() Catch loError As Exception oApp.ErrorSetup(loError) lcString = "" End Try Return lcString End FunctionI have also this function to do the same but for binary files:
' Same as FileToStr() but for binary files ' This is used when you want to take a JPG, for example, and encode it as Base64 into a XSL ' expC1 File name Public Function FileToStrBinary(ByVal tcFileName As String) As String Dim loFile As IO.StreamReader Dim lcString As String Try loFile = New IO.StreamReader(tcFileName, System.Text.Encoding.Default) lcString = loFile.ReadToEnd() loFile.Close() Catch loError As Exception oApp.ErrorSetup(loError) lcString = "" End Try Return lcString End FunctionThe second function serves for reading a file such as Logo.jpg and getting its content into a variable. One need for that is to be able to encode that content into a Base64 and drop that into a XSL file. If I would use the FileToStr() function for that, I would end up in a 18k length instead of 35k length when Logo.jpg is of size 35k for example. Using FileToStrBinary() preserves the exact content as is.