|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
File to string and back againvb.net 1.1 Windows application
Hey,, In a bit of a hurry,, does anyone know a way to turn a file in to a string,, such as a jpeg or pdf,, then turn that string back in to the original file? Cheers Bonzol wrote:
> vb.net 1.1 Windows application Sure... Read the binary data into a byte array. Base64 encode it.> > Hey,, In a bit of a hurry,, does anyone know a way to turn a file in to > a string,, such as a jpeg or pdf,, then turn that string back in to the > original file? > > Cheers You know have a string. To get it back to the file, decode it to a byte array and write the data to a file... Option Strict On Option Explicit On Imports System Imports System.IO Module Module1 Private Const INPUT_FILE As String = "c:\WINDOWS\Coffee Bean.bmp" Private Const OUTPUT_FILE As String = "Coffee Bean.bmp" Sub Main() Dim buffer() As Byte ' read the bitmap Using fstream As FileStream = File.OpenRead(INPUT_FILE) ReDim buffer(CInt(fstream.Length - 1)) fstream.Read(buffer, 0, buffer.Length) End Using ' convert to a base64 string Dim stringValue As String = Convert.ToBase64String(buffer) Console.WriteLine(stringValue) ' now convert it back to a byte array buffer = Convert.FromBase64String(stringValue) ' write it to the new file Using fstream As FileStream = File.OpenWrite(OUTPUT_FILE) fstream.Write(buffer, 0, buffer.Length) End Using End Sub End Module
Read legacy vb5 files with variant declare in vb.net
Running an Access macro from a VB.NETprogram need help on optional arg ADOX add bool field Overlapping controls How to determen the object ? WEB combobox won't fire event Redrawing on GDI+ clicking on a DataGridView's DataSource property throws exception in designer Set Focus to textbox on tab control |
|||||||||||||||||||||||