473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

File to string and back again

vb.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

Oct 7 '06 #1
1 3351

Bonzol wrote:
vb.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
Sure... Read the binary data into a byte array. Base64 encode it.
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

Oct 7 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: spike | last post by:
Im writing a program to search for a string in a binary file. And it works. The problem is: It is sooo slow! how can i make it faster? It takes 27 seconds just to search a 5 meg file. I guess it...
5
by: Chathu | last post by:
Hello everyone........... I have a problem on retriving a content of a binary file I wrote into. My program user structures, dynamic allocation of memory and files. I take the infomation into a...
7
by: moondaddy | last post by:
I want to dynamically create a JavaScript file and cache it on the client for re-use. I know how to write javascript to a web page from the code behind, but I don't know how to actually create a...
12
by: Adam J. Schaff | last post by:
I am writing a quick program to edit a binary file that contains file paths (amongst other things). If I look at the files in notepad, they look like: ...
13
by: Marc | last post by:
The first part of the below writes the name and location of all buttons on a from to a text file. The second part reads that information back in and recreates the buttons. My problem is reading...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
19
by: Lee Crabtree | last post by:
Is there a class in the framework that allows me read text from a file in an unbuffered manner? That is, I'd like to be able to read lines in the same manner as StreamReader.ReadLine(), but I also...
11
by: Lamer | last post by:
I was wondering how to save PHP variables to a txt file and then retrieve them again. Example: There is an input box, after submitted the stuff that was written in the input box will be saved...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.