Solved

Converting CSV file data to Byte

Posted on 2014-09-09
7
419 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 32

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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

10 Experts available now in Live!

Get 1:1 Help Now