>I have the following function to get the content of a file into a variable:
>
>
> ' 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 Function
>
>
>I 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 Function
>
>
>The 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.
>
>The question is how can I use the same function to achieve both purposes? Because, if I use FileToStrBinary() to read a simple text file containing French characters, I am loosing them all. The key is the True parameter in FileToStr() which will preserve the French characters. But, one function is using True and the other one System.Text.Encoding.Default() which produces two different results which serves presently both of my needs. Would it there be a way to have everything into one function where binary files would be read ok as well as text files containing French characters?
Michel,
IMHO VFP FileToStr() equivalant is BinaryReader not StreamReader.
Cetin