Results 1 to 11 of 11

Thread: [2005] sending file through network

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    [2005] sending file through network

    Hello everybody
    I want to read all of the data in an binary file like gif file to send the file through network. what is the best way? I using winsock but I don't know how to read all data in the file. I used this but it dosn't work
    Dim st As FileStream = File.Open("C:\test.gif", FileMode.Open)
    Dim binaryFile As New BinaryReader(st)
    Dim FData As String
    FData = MsgBox(binaryFile.ReadString())
    While (EOF(binaryFile.GetHashCode()))
    MsgBox(FData)
    FData = MsgBox(binaryFile.ReadString())
    End While

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    any body?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    is it a hard question?!!

  4. #4
    Addicted Member sauronsmatrix's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    133

    Re: [2005] sending file through network

    BUMP

    I'm trying to do something similar as well... If I make any progress I'll let you know; I bookmarked the thread.

    Oh, and as for reading the data:

    Code:
            Dim dialog As New Windows.Forms.OpenFileDialog
            Dim blah As DialogResult = dialog.ShowDialog()
            If blah = Windows.Forms.DialogResult.Cancel Then Exit Sub
            Dim st As FileStream = File.Open(dialog.FileName, FileMode.Open)
            Dim fileread As New StreamReader(st)
            Dim FData As String = fileread.ReadToEnd()
            st.Close()
            fileread.Close()
            TextBox1.Text = FData
    That's how to read the data easily. I saw you used a binary reader though. Is that required for sending the file through the network?
    Last edited by sauronsmatrix; Jul 5th, 2008 at 01:46 AM.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    Thx alot bro , but that code would be a bad sol for reading a big files!
    It would be good right now for reading the gif small files. I will try it
    Thx again

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    it dosn't work with me!! Plz if anybody have the way to read a binary file and put the read data into a string variable, tell us?!
    thx

  7. #7
    Addicted Member sauronsmatrix's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    133

    Re: [2005] sending file through network

    Made some progress my friend! I got the binary reading down.

    Heres the code:
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            TextBox1.Text = ""
            Dim dialog As New Windows.Forms.OpenFileDialog
            Dim blah As DialogResult = dialog.ShowDialog()
            If blah = Windows.Forms.DialogResult.Cancel Then Exit Sub
            Dim st As FileStream = File.Open(dialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)
            Dim fileread As New StreamReader(st)
            Dim filedata As String = fileread.ReadToEnd
            TextBox1.Text = TextToBinary(filedata)
            st.Close()
            fileread.Close()
        End Sub
        Public Function TextToBinary(ByVal Text As String, Optional ByVal Separator As String = " ") As String
            Dim oReturn As New StringBuilder
            ' Convert to ASCII and go through all the bytes
            For Each Character As Byte In ASCIIEncoding.ASCII.GetBytes(Text)
                oReturn.Append(Convert.ToString(Character, 2).PadLeft(8, "0"))
                oReturn.Append(Separator)
            Next
            Return oReturn.ToString
        End Function
    I took the TextToBinary Function off some site, its not mine. But yeah, it works. Although loading large files does take long, but you can use a BackgroundWorker to solve that mess.

    Now, on to the actual networking.... X__X

    Also, you need an import:

    Code:
    Imports System.Text
    and obviously
    Code:
    Imports System.IO

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    why conversion I didn't get it? I used the reading code and imediatly save the content of the filedata into another file but it is currupted??!

  9. #9
    Addicted Member sauronsmatrix's Avatar
    Join Date
    Jun 2008
    Location
    USA
    Posts
    133

    Re: [2005] sending file through network

    let me see the code you are using to save the file

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    Dim F As Integer = FreeFile()
    FileOpen(F, "c:\tes.gif", OpenMode.Binary)
    FilePut(F, FData)
    FileClose(F)

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2005
    Posts
    265

    Re: [2005] sending file through network

    hello!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width