Read/write binary file (VB) : Binary File « File Directory « ASP.Net

ASP.Net
1. ADO.net Database
2. Ajax
3. Asp Control
4. Collections
5. Components
6. Data Binding
7. Development
8. File Directory
9. HTML Control
10. Language Basics
11. Login Security
12. Mobile Control
13. Network
14. Page
15. Request
16. Response
17. Server
18. Session Cookie
19. Sitemap
20. Theme Style
21. User Control and Master Page
22. Validation by Control
23. Validation by Function
24. WebPart
25. WPF
26. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
ASP.Net » File Directory » Binary File 
Read/write binary file (VB)

<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
    Dim objBinaryWriter As BinaryWriter
    Dim objBinaryReader As BinaryReader
    
    Sub WriteButton_Click(sender As Object, e As EventArgs)
        Dim objFileStream As FileStream
        Try
               objFileStream = New FileStream("myFileVB.bin", FileMode.Create)
               objBinaryWriter = New BinaryWriter(objFileStream)
    
               Dim Name As String = NameTextBox.Text
               Dim Age As Integer = Int32.Parse(AgeTextBox.Text)
               Dim Sex As Char = Char.Parse(SexTextBox.Text)
    
               objBinaryWriter.Write(Name)
               objBinaryWriter.Write(Age)
               objBinaryWriter.Write(Sex)
    
        Catch FileEx As FileNotFoundException
            MessageLabel.Text = FileEx.Message()
            Exit Sub
        Catch Ex As Exception
            MessageLabel.Text = Ex.Message()
            Exit Sub
        End Try
    
        WriteBinaryPanel.Visible = False
        ReadBinaryPanel.Visible = True
    
    End Sub
    
  Sub ReadButton_Click(Sender As Object, e As EventArgs)

    Dim objFileStream As FileStream

    Try
        objFileStream = New FileStream("C:\myFileVB.bin", FileMode.Open)
        objBinaryReader = New BinaryReader(objFileStream)

        NameLabel.Text = "Your Name: " & objBinaryReader.ReadString()
        AgeLabel.Text = "Your Age: " & objBinaryReader.ReadInt32()
        SexLabel.Text = "Your Sex: " & objBinaryReader.ReadChar()
    Catch FileEx As FileNotFoundException
      MessageLabel.Text = FileEx.Message()
      Exit Sub
    Catch Ex As Exception
      MessageLabel.Text = Ex.Message()
      Exit Sub
    End Try

  End Sub

</script>
<html>
  <head>
  </head>
  <body>
    <form runat="server">
      <p>
        <asp:Panel id="WriteBinaryPanel" Runat="Server">
          <p>
            Please enter your Name:
            <asp:TextBox id="NameTextBox" runat="server"></asp:TextBox>
          </p>
          <p>
            Please enter your Age:
            <asp:TextBox id="AgeTextBox" runat="server"></asp:TextBox>
          </p>
          <p>
            Please enter your Sex:
            <asp:TextBox id="SexTextBox" 
                         runat="Server" 
                         MaxLength="1" 
                         Columns="1"></asp:TextBox>
            (M/F)
          </p>
          <p>
            <asp:Button id="WriteButton" 
                        onclick="WriteButton_Click" 
                        runat="server" 
                        Text="Write It!"></asp:Button>
          </p>
        </asp:Panel>
        <asp:Panel id="ReadBinaryPanel" Runat="Server">
          <p>
            <asp:Button id="ReadButton" 
                        onclick="ReadButton_Click" 
                        runat="server" 
                        Text="Read It!"></asp:Button>
          </p>
          <p>
            <asp:Label id="NameLabel" Runat="Server"></asp:Label>
          </p>
          <p>
            <asp:Label id="AgeLabel" Runat="Server"></asp:Label>
          </p>
          <p>
            <asp:Label id="SexLabel" Runat="Server"></asp:Label>
          </p>
        </asp:Panel>
      </p>
      <p>
        <asp:Label id="MessageLabel" 
                   runat="server" 
                   EnableViewState="False"></asp:Label>
      </p>
    </form>
  </body>
</html>

 
Related examples in the same category
1. Read/write binary file (C#)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.