Solved

Converting CSV file data to Byte

Posted on 2014-09-09
7
444 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New to SOAP and need some direction 10 46
Icons and Colors for Terms 3 24
How would you add MULTITHREADING to the attached C# code? 4 52
C#.NET and microsoft certification. 3 34
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 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

19 Experts available now in Live!

Get 1:1 Help Now