Solved

encode file and send

Posted on 2006-06-10
2
181 Views
Last Modified: 2010-04-23
I have an app that is using sockets to dend data. Right now i can encode text from a textbox and send it to the server app where it is read, no problem.

What i need to do is grab a file that is already in binary form and send it to the server where i need to read it.
Can anyone give me pointers, i am lost in streamriters and advice from every corner of the web i can find. Seems simple but cant implement it

I tried this but all it sends is the file name (C:\blah\blah.dat etc) across to the server, not the file itself

Dim ofd As New OpenFileDialog
 ofd.ShowDialog(Me)
Dim Data() As Byte = System.Text.Encoding.UTF8.GetBytes(ofd.FileName)
openedSocket.Send(Data)


Thanks!!
0
Comment
Question by:Halon
  • 2
2 Comments
 
LVL 9

Accepted Solution

by:
jrscherer earned 500 total points
ID: 16879731
There are so many ways to open and read a file. It is confusing.

Here is a simple one, adapted to your problem:

        Dim ofd As New OpenFileDialog
        If ofd.ShowDialog(Me) <> Windows.Forms.DialogResult.OK Then Exit Sub
        Dim sr As New StreamReader(ofd.FileName)
        Dim Data() As Byte = System.Text.Encoding.UTF8.GetBytes(sr.ReadToEnd)
        sr.Close()
        sr.Dispose()

Jack.net
0
 
LVL 9

Expert Comment

by:jrscherer
ID: 16879737
Don't forget to import the namespace:  Imports System.IO  jack.net
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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