Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

convert bin file to text file in c#

Posted on 2006-04-03
8
Medium Priority
?
1,819 Views
Last Modified: 2010-08-05
Hi,

I need to convert a bin file to txt file in C#. Please show me some example code.

Thanks

Lanac
0
Comment
Question by:lanac222
  • 4
  • 2
6 Comments
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16363093
If "bin" refers to a binary file, then you should know that at the storage level, there is no difference between files containing binary data and those containing text; both are stored in binary format. You can open both files in whatever mode you like. The problem is that when you open a binary file for processing in text mode, you get unreadable characters (and possibly the file truncates at the first null character encountered, which is used to specify the End-Of-File for text files). Similarly, when you open a text file in binary access mode, you process the file (read/write) as a stream of bytes, which is inconvenient.

_______________

  Nayer Naguib
0
 
LVL 14

Expert Comment

by:nayernaguib
ID: 16363184
Using sample code listed on the following page, you can try opening and manipulating both types of files (binary/text) in both modes:

  http://www.ondotnet.com/pub/a/dotnet/2002/08/05/io.html?page=5

_______________

  Nayer Naguib
0
 

Author Comment

by:lanac222
ID: 16363674
but i'd like to convert the binary data to man readable text.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:nayernaguib
ID: 16366334
Usually, binary files do not contain readable text. Try opening some MP3 or AVI file using Notepad and take a look at its contents!
If you are sure that some file contains readable text (even if the extension is not "TXT"), you can simply open the file in text mode. Otherwise, you will not be interested in reading binary data in text mode.

_______________

  Nayer Naguib
0
 

Author Comment

by:lanac222
ID: 16370911
The file contents are numeric data generated at a POS. It should be readable text. But when I open with notepad it still shows binary code.
0
 
LVL 14

Accepted Solution

by:
nayernaguib earned 500 total points
ID: 16372408
This means that the file contents were somehow encoded (not necessarily for security reasons, maybe this is just a standard file format or something). Now what you did was *exactly* opening a file for reading in text mode! There will be nothing you can do better than that using C# unless you know first how to decode the file.

_______________

  Nayer Naguib
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question