Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 26th, 2003, 09:47 AM
Registered User
 
Join Date: Jun 2003
Location: San Antonio, tx, USA.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read Text file and convert to Binary file VB.net

Hi!
Can someone show me how to convert a text file to a binary file.
Thanks
sjp
Reply With Quote
  #2 (permalink)  
Old November 11th, 2004, 09:19 AM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
can u send me the code on how to convert from text file to binary file?

Reply With Quote
  #3 (permalink)  
Old December 8th, 2004, 06:13 AM
Registered User
 
Join Date: Jan 2004
Location: , , India.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

Here's a sample code to convert a text file to a binary file

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Class1

    Public Sub BinarySerialize()
        'Create a streamreader class
        Dim objStreamReader As StreamReader
        'open the file
        objStreamReader = File.OpenText("c:\\Mystore1.txt")
        'Read the file storing it in the readfile string
        Dim readfile As String = objStreamReader.ReadToEnd()
        Dim flStream As FileStream = New FileStream("c:\\myStore.txt", FileMode.OpenOrCreate, FileAccess.Write)
        Try
            Dim bFormatter As BinaryFormatter = New BinaryFormatter
            bFormatter.Serialize(flStream, readfile)
        Finally
            flStream.Close()
            objStreamReader.Close()
        End Try
    End Sub

Cheers,
Monica
Reply With Quote
  #4 (permalink)  
Old June 29th, 2007, 01:51 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I checked with your code,but its not working its showing same text as what i passed text file,only the first line of the file got affected.
can u check the code and send it once again please




Quote:
quote:Originally posted by Monica
 Hi,

Here's a sample code to convert a text file to a binary file

Imports System.IO
Imports System.Runtime.Serialization.Formatters.Binary

Public Class Class1

    Public Sub BinarySerialize()
        'Create a streamreader class
        Dim objStreamReader As StreamReader
        'open the file
        objStreamReader = File.OpenText("c:\\Mystore1.txt")
        'Read the file storing it in the readfile string
        Dim readfile As String = objStreamReader.ReadToEnd()
        Dim flStream As FileStream = New FileStream("c:\\myStore.txt", FileMode.OpenOrCreate, FileAccess.Write)
        Try
            Dim bFormatter As BinaryFormatter = New BinaryFormatter
            bFormatter.Serialize(flStream, readfile)
        Finally
            flStream.Close()
            objStreamReader.Close()
        End Try
    End Sub

Cheers,
Monica
Reply With Quote
  #5 (permalink)  
Old June 29th, 2007, 06:53 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: India.
Posts: 224
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to ashu_from_india Send a message via Yahoo to ashu_from_india
Default

just open a BinaryReader and open the file...it will return binary data only

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert HTML File to PDF file in vb.net gaurikhot .NET Framework 2.0 4 June 16th, 2014 02:33 AM
VB 2005 question, binary to text file conversion pitcher General .NET 0 September 24th, 2007 07:45 PM
How to convert Binary file to Text File pbassett Beginning VB 6 1 May 9th, 2006 03:51 AM
SQL 2000 database / text file / binary file pallone Javascript How-To 3 January 28th, 2005 01:26 PM
Read text file and out to serial port VB.net noomkmitl Pro VB.NET 2002/2003 0 December 27th, 2004 08:44 AM



All times are GMT -4. The time now is 05:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.