Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting to Base64
Message
De
26/08/2010 03:28:57
 
 
À
26/08/2010 00:15:49
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01478537
Message ID:
01478547
Vues:
29
>I am using this to XML a file into a Base64 syntax:
>
>
>Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(lcXml))
>
>
>And, I am using this to do the reverse process:
>
>
>        ' Create a file
>        ' expC1 Node
>        ' expC2 File
>        Public Function CreateFile(ByVal tcXML As String, ByVal tcFile As String) As Boolean
>            Dim lcFile As String = ""
>            Dim loByte() As Byte = Nothing
>            Dim loFileStream As System.IO.FileStream = Nothing
>
>            ' Reset the values
>            cError = ""
>
>            Try
>                ReDim loByte(tcXML.Length)
>
>                ' Decode the value
>                loByte = Convert.FromBase64String(tcXML)
>
>                ' Create the file
>                loFileStream = New System.IO.FileStream(tcFile, System.IO.FileMode.Create)
>
>                ' Write the file
>                loFileStream.Write(loByte, 0, loByte.Length)
>
>                ' Close the file
>                loFileStream.Close()
>
>            Catch loError As Exception
>                cError = loError.Message
>                Return False
>            End Try
>
>            Return True
>        End Function
>
>
>But, obviously, I do not end up with the same file. So, something is wrong in my process. Anyone would be able to know the proper way to get the file back?

Not clear how the two bits join up. IAC isn't all you really need something like this:
'Save
Dim lcXml As String = "<Test>Hello</Test>"
Dim writer As New System.IO.StreamWriter("c:\Save")
writer.Write(Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(lcXml)))
writer.Close()

'Restore
Dim reader As New System.IO.StreamReader("c:\Save")
Dim lcXmlback As String = System.Text.Encoding.Default.GetString(Convert.FromBase64String(reader.ReadToEnd()))
reader.Close()
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform