Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Two functions into one
Message
De
27/06/2006 11:03:59
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
27/06/2006 10:40:06
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01131998
Message ID:
01132010
Vues:
13
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform