Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Convert a file to a string
Message
De
25/07/2014 09:37:43
 
 
À
25/07/2014 03:55:33
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01604630
Message ID:
01604652
Vues:
32
>The only difference between the two is that 'IO.StreamReader(lcFile, True)' will use UTF8Encoding if it can't detect the encoding and ' IO.StreamReader(lcFile, System.Text.Encoding.Default)' will use the system code page. Seems to me first is safer since the latter is unpredictable -see the 'Caution' section here:
>http://msdn.microsoft.com/en-us/library/system.text.encoding.default(v=vs.110).aspx
>
>Rick has a post here on the problems: http://weblog.west-wind.com/posts/2007/Nov/28/Detecting-Text-Encoding-for-StreamReader
>
> I'd only suggest that you could use Encoding.GetPreamble() to check the headers.

I cannot use the first on some FileToStr conversion I need to do. For example, a JPG, I have to use FileToStringBinary(). The same applies for some other conversions. For example, I have a method to convert a file to Base64:
    ' Convert to Base64
    Public Function ConvertToBase64() As Boolean
        Dim llSuccess As Boolean = False
        Dim loFileFunction As Framework.FileFunction = Nothing

        ' Get the proper definition as per the current scope
        If oProcess Is Nothing Then
            loFileFunction = New Framework.FileFunction(oApp)
        Else
            loFileFunction = New Framework.FileFunction(oProcess)
        End If

        ' Reset the values
        cEncoded = ""
        cMessage = ""

        Try

            ' If we cannot create a string from the file
            loFileFunction.cFile = cFile
            If Not loFileFunction.FileToStringBinary() Then
                cMessage = loFileFunction.cMessage
                Return False
            End If

            cEncoded = Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(loFileFunction.cString))

            llSuccess = True
        Catch loError As Exception
            cMessage = loError.Message
        End Try

        ' Reset the values
        cFile = ""

        Return llSuccess
    End Function
I first need to collect the file into a string before encoding it.

I do however have a method for ConvertToBase64FromByte() and ConvertToBase64FromString().
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform