Click here to Skip to main content
15,908,264 members
Home / Discussions / C#
   

C#

 
AnswerRe: Converting *ANY* file to Binary and back Pin
mav.northwind12-Oct-07 20:22
mav.northwind12-Oct-07 20:22 
GeneralRe: Converting *ANY* file to Binary and back Pin
Ian Uy12-Oct-07 20:30
Ian Uy12-Oct-07 20:30 
GeneralRe: Converting *ANY* file to Binary and back Pin
led mike12-Oct-07 20:34
led mike12-Oct-07 20:34 
GeneralRe: Converting *ANY* file to Binary and back Pin
Ian Uy12-Oct-07 21:18
Ian Uy12-Oct-07 21:18 
GeneralRe: Converting *ANY* file to Binary and back Pin
Daniel Grunwald12-Oct-07 23:42
Daniel Grunwald12-Oct-07 23:42 
GeneralRe: Converting *ANY* file to Binary and back Pin
Ian Uy12-Oct-07 23:53
Ian Uy12-Oct-07 23:53 
GeneralRe: Converting *ANY* file to Binary and back Pin
Colin Angus Mackay13-Oct-07 0:01
Colin Angus Mackay13-Oct-07 0:01 
AnswerRe: Converting *ANY* file to Binary and back Pin
Guffa13-Oct-07 0:19
Guffa13-Oct-07 0:19 
Ian Uy wrote:
I am wondering if there is a way to convert a certain file(.EXE,.JPG) to Binary/Byte


The files are already binary data. All files are always binary data, even text files are binary data. It's only when you read a text file as text that it becomes text, otherwise it's only bytes.

Reading a file is quite easy:

byte[] data = File.ReadAllBytes(@"c:\test.jpg");

Ian Uy wrote:
For example, I have a certain Picture.jpg. I want to convert it to binary/Byte, and save it as a TEXT FILE.


You can't save binary data as text. If you want the binary data as text, you have to convert it, for example using base 64:

string dataText = Convert.ToBase64String(data);

Each character (which is a 16 bit unicode character) now contains 6 bits of information. Now you can save the string as a text file.

(Note that the text will be encoded to binary format (usually using utf-8 encoding) when saved as a file, as files always are binary.)

When you have read back the text file as a string, you can convert it back to the original data:

byte[] data = Convert.FromBase64String(dataText);

---
single minded; short sighted; long gone;

GeneralRe: Converting *ANY* file to Binary and back Pin
Ian Uy13-Oct-07 0:59
Ian Uy13-Oct-07 0:59 
GeneralRe: Converting *ANY* file to Binary and back Pin
Guffa13-Oct-07 3:55
Guffa13-Oct-07 3:55 
QuestionBegin printing at row x column y Pin
Roger CS12-Oct-07 18:17
Roger CS12-Oct-07 18:17 
AnswerRe: Begin printing at row x column y Pin
led mike12-Oct-07 20:33
led mike12-Oct-07 20:33 
GeneralRe: Begin printing at row x column y Pin
Roger CS12-Oct-07 23:03
Roger CS12-Oct-07 23:03 
GeneralRe: Begin printing at row x column y Pin
Dave Kreskowiak13-Oct-07 3:04
mveDave Kreskowiak13-Oct-07 3:04 
GeneralRe: Begin printing at row x column y [modified] Pin
Roger CS13-Oct-07 11:29
Roger CS13-Oct-07 11:29 
GeneralRe: Begin printing at row x column y Pin
Roger CS14-Oct-07 15:17
Roger CS14-Oct-07 15:17 
GeneralRe: Begin printing at row x column y Pin
led mike15-Oct-07 4:52
led mike15-Oct-07 4:52 
AnswerRe: Begin printing at row x column y Pin
darkelv14-Oct-07 19:04
darkelv14-Oct-07 19:04 
GeneralRe: Begin printing at row x column y Pin
Roger CS15-Oct-07 4:15
Roger CS15-Oct-07 4:15 
QuestionThread & UI Pin
Archyami12-Oct-07 17:11
Archyami12-Oct-07 17:11 
AnswerRe: Thread & UI Pin
led mike12-Oct-07 20:26
led mike12-Oct-07 20:26 
AnswerRe: Thread & UI Pin
mav.northwind12-Oct-07 20:30
mav.northwind12-Oct-07 20:30 
GeneralRe: Thread & UI Pin
Archyami12-Oct-07 22:42
Archyami12-Oct-07 22:42 
QuestionDelegate awkwardness---is there a better way? Pin
Domenic Denicola12-Oct-07 16:35
Domenic Denicola12-Oct-07 16:35 
AnswerRe: Delegate awkwardness---is there a better way? Pin
PIEBALDconsult12-Oct-07 16:43
mvePIEBALDconsult12-Oct-07 16:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.