2

I have an image which is of type varbinary in db.

In BO layer, it is declared as Byte[].

    public Byte[] Image
    {
         get { return p_image; }
         set { p_image = value; }
    }

To assign its value in BO layer, I used

objBO.Image = FileUploadControl.FileContent

Its throws the error

Connot convert System.IO.Stream to Byte[]

Can anybody help in choosing the parameter of FileUploadControl that can be converted to Byte[]?

Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124
user2138814
  • 69
  • 3
  • 17

2 Answers2

3

Use FileUpload.FileBytes property to get Byte[] from the FileUploadControl

Gets an array of the bytes in a file that is specified by using a FileUpload control.

FileUpload fileUpload = new FileUpload();
Byte[] fileBytes = fileUpload.FileBytes;

The FileUpload control does not automatically read the file from the client. You must explicitly provide a control or mechanism to allow the user to submit the specified file. For example, you can provide a button that the user can click to upload the file. The code that you write to save the specified file could call the FileBytes property, which returns the contents of the file.

Habib
  • 219,104
  • 29
  • 407
  • 436
1

instead of FileUploadControl.FileContent you must use FileUploadControl.FileBytes

Filecontent gives you you the stream, so either convert the stream into bytes or directly use FileBytes

Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124