Solved

Converting CSV file data to Byte

Posted on 2014-09-09
7
511 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 34

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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

740 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