how can I save the contents of a fileupload in a byte array?

0

Good evening everyone, my query is as follows.

I have an asp.net web forms form on vb.net where I have an asp: fileupload control like this:

   <asp:FileUpload ID="UpLoadEstudiantes" runat="server" 
   AllowMultiple="False" CssClass="fileContainer"/> 

What I want in the code behind is to get that file from the fileupload and convert it to an array of bytes to send it to a method that receives this array of bytes and processes it.

The problem is that I try to get the contents of the fileupload and convert it to a byte array but I can not get through the array of bytes with the file.

This is one of the ways you try to fill an array of bytes with the contents of the fileupload.

    Dim ms As New MemoryStream()
    UpLoadEstudiantes.PostedFile.InputStream.CopyTo(ms)
    Dim byts = ms.ToArray()
    ms.Dispose()

and I have this error frequently when using the InputStream or the ContentFile.

    
asked by ASP.NEET 24.11.2017 в 06:07
source

1 answer

0

In the property FileBytes of FileUpload you already have the contents of the file in an array of bytes:

If UpLoadEstudiantes.HasFile Then
    Dim filelen As Integer = UpLoadEstudiantes.PostedFile.ContentLength
    Dim byts(filelen-1) As Byte
    byts = UpLoadEstudiantes.FileBytes

End If
    
answered by 24.11.2017 в 08:00