Solved

Converting CSV file data to Byte

Posted on 2014-09-09
7
481 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 63

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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 63

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 63

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

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.

830 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