|
-
Jul 4th, 2008, 09:27 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jul 4th, 2008, 10:16 AM
#2
Thread Starter
Hyperactive Member
Re: [2005] sending file through network
-
Jul 4th, 2008, 01:44 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] sending file through network
-
Jul 5th, 2008, 01:37 AM
#4
Addicted Member
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.
-
Jul 5th, 2008, 02:10 AM
#5
Thread Starter
Hyperactive Member
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
-
Jul 5th, 2008, 02:44 AM
#6
Thread Starter
Hyperactive Member
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
-
Jul 5th, 2008, 03:11 AM
#7
Addicted Member
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
-
Jul 5th, 2008, 03:47 AM
#8
Thread Starter
Hyperactive Member
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??!
-
Jul 5th, 2008, 03:50 AM
#9
Addicted Member
Re: [2005] sending file through network
let me see the code you are using to save the file
-
Jul 5th, 2008, 04:06 AM
#10
Thread Starter
Hyperactive Member
Re: [2005] sending file through network
Dim F As Integer = FreeFile()
FileOpen(F, "c:\tes.gif", OpenMode.Binary)
FilePut(F, FData)
FileClose(F)
-
Jul 5th, 2008, 01:36 PM
#11
Thread Starter
Hyperactive Member
Re: [2005] sending file through network
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|