Solved

encode file and send

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

14 Experts available now in Live!

Get 1:1 Help Now