Solved

encode file and send

Posted on 2006-06-10
2
177 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now