Reputation: 41
My given code has an error of type conversion
int imglength = FileUpload2.PostedFile.ContentLength;
byte imgarray=new byte[imglength];
Upvotes: 4
Views: 18644
Reputation: 2509
Check this:
int imgLength = FileUpload2.PostedFile.ContentLength;
byte[] revLength= BitConverter.GetBytes(imgLength);
Array.Reverse(revLength);
byte[] imgLengthB = revLength;
Upvotes: 0
Reputation: 2587
You can use the below code:
int imageSize = fuImage.PostedFile.ContentLength;
System.IO.Stream imageStream = fuImage.PostedFile.InputStream;
byte[] imageContent = new byte[imageSize];
int status = imageStream.Read(imageContent, 0, imageSize);
This code coverts postedfile to byte stream
Upvotes: 1
Reputation: 9947
you can not assign a byte array to byte
try this
byte[] bytearray = new byte[imglength];
Upvotes: 4
Reputation: 28403
Structure is like this
byte[] Buffer = new byte[imglength];
Upvotes: 1
Reputation: 28530
You're trying to assign an array of bytes (byte[]
) to a single byte, hence the error.
Try the following code:
byte[] imgarray = new byte[imglength];
Upvotes: 8