troubleshooting Question

C#, byte streaming with StreamReader problem

Avatar of jazzIIIlove
jazzIIIloveFlag for Sweden asked on
8 Comments2 Solutions4343 ViewsLast Modified:
Hi there;

I am trying to do byte streaming with C#. The application must reach the FTP server (which he can) and grab the file (which is not a text file), some encrypted file.

I can reach the server and list the directories with no problem. My problem is regarding streaming the file content. In fact, I have a compile time error in the lines:
int bytesRead = reader.Read(buffer, 0, buffer.Length);
and in the similar line in while.

I am sure it is true since the function takes the exact params but the compiler says:

Error 1 The best overloaded method match for 'System.IO.TextReader.Read(char[], int, int)' has some invalid arguments      
Error 2 Argument '1': cannot convert from 'byte[]' to 'char[]'      

My code is as follows:

Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
MemoryStream memStream = new MemoryStream();
int Size = 1024;
            byte[] buffer = new byte[Size];
            int bytesRead = reader.Read(buffer, 0, buffer.Length);
            while (bytesRead != 0) //while(true)
                    //Try to read the data
                    bytesRead = reader.Read(buffer, 0, buffer.Length);
                      //Write the downloaded data
                        memStream.Write(buffer, 0, bytesRead);
                byte[] downloadedData = new byte[0];
                //Convert the downloaded stream to a byte array
                downloadedData = memStream.ToArray();

Best regards.

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros