Solved

Converting CSV file data to Byte

Posted on 2014-09-09
7
454 Views
Last Modified: 2014-09-14
I am working on an existing piece of VB.Net Code which is sending data from CSV file to FTP and over there they recreate the csv file.

How to read the variable data which is  in the Parameter. I want to ensure whether the variable data is carrying the actual values from CSV file in the Byte format.

ByVal data As Byte()

Public Function UploadFileFromStream(ByVal data As Byte(), ByVal fileName As String) As Boolean

        Try
            _ftpWebRequest = CType(WebRequest.Create(_uri & fileName), FtpWebRequest)
            _ftpWebRequest.Credentials = New System.Net.NetworkCredential(_userId, _password, _domain)
            _ftpWebRequest.KeepAlive = True
            _ftpWebRequest.UseBinary = _useBinary

            _ftpWebRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

            Dim prxy As New System.Net.WebProxy()
            prxy.BypassProxyOnLocal = True
            _ftpWebRequest.Proxy = prxy

            Using request As System.IO.Stream = _ftpWebRequest.GetRequestStream()

                request.Write(data, 0, data.Length)
                request.Close()

            End Using

        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try

        Return True

    End Function

Open in new window

0
Comment
Question by:chokka
  • 3
  • 3
7 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40312361
Huh? See Stream.Write.. so it should work.

But why don't you use a stream instead?
0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40312379
Hi chokka;

See if this gives you what you are looking for.

Dim base64String As String 
base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length)

Open in new window

0
 

Author Comment

by:chokka
ID: 40312397
@Fernado, What variable is that binaryData

Visual Studio Intellisense points me to change it to BinaryReader or BinaryWriter
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40312404
binaryData = Your byte array variable name.
0
 

Accepted Solution

by:
chokka earned 0 total points
ID: 40312560
This piece of syntax helped me. Your syntax doesn't returned the  actual value. Indeed, it was displaying the value in an encrypted  or some binary format.

Dim str As String
str = System.Text.Encoding.UTF8.GetString(data)

Open in new window

0
 
LVL 62

Expert Comment

by:Fernando Soto
ID: 40312626
Did someones post help you to come up with the solution?
0
 

Author Closing Comment

by:chokka
ID: 40321527
My answer returned actual value
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 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

15 Experts available now in Live!

Get 1:1 Help Now