How to convert a HttpPostedfile into a Byte()

peter liles 556 Reputation points
2023-12-06T11:14:02.1566667+00:00

For Each postedFile As HttpPostedFile In PictureUpload2.PostedFiles

i am trying to get the postedfile and convert to byte() like:

 Using s As Stream = PostedFile.InputStream


        Using br As New BinaryReader(s)
        Dim image As Byte() = br.ReadBytes(CType(s.Length, Int32))

without success. Only when i execute the following will it obtain the Byte Array ? 
   Dim image As Byte() = PictureUpload2.FileBytes

I am trying to recreate a thumbnail image of all the PostedFiles !
Developer technologies ASP.NET Other
{count} votes

1 answer

Sort by: Most helpful
  1. AgaveJoe 30,126 Reputation points
    2023-12-06T13:21:41.29+00:00

    The official docs has source code that reads a HttpPostedFile.InputStream into a byte array.

    HttpPostedFile.InputStream Property

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.