mendez7
mendez7

Reputation: 195

Stream CopyTo() method in c# not working as I want it to

What am I doing Wrong ?. This is my code snippet below:

PhotoResult e;
using (var filebytes = new MemoryStream())
            {
                    e.ChosenPhoto.CopyTo(filebytes);

                    Debug.WriteLine(e.ChosenPhoto.Length); // Outputs the correct length
                    Debug.WriteLine(filebytes.Length);  //Outputs 0

              }

Upvotes: 1

Views: 1187

Answers (1)

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

Most likely, you need to reset the position of e.ChosenPhoto before performing the copy:

e.ChosenPhoto.Position = 0;

The documentation states:

Copying begins at the current position in the current stream

Upvotes: 6

Related Questions