[英]Cannot convert System.IO.Stream to Byte[]
I have an image which is of type varbinary
in db. 我有一个在db中类型为
varbinary
的图像。
In BO layer, it is declared as Byte[]
. 在BO层中,它声明为
Byte[]
。
public Byte[] Image
{
get { return p_image; }
set { p_image = value; }
}
To assign its value in BO layer, I used 为了在BO层中分配其值,我使用了
objBO.Image = FileUploadControl.FileContent
Its throws the error 它抛出错误
Connot convert System.IO.Stream to Byte[]
不能将System.IO.Stream转换为Byte []
Can anybody help in choosing the parameter of FileUploadControl
that can be converted to Byte[]
? 有人可以帮助选择可以转换为
Byte[]
的FileUploadControl
参数吗?
Use FileUpload.FileBytes
property to get Byte[]
from the FileUploadControl
使用
FileUpload.FileBytes
属性从FileUploadControl
获取Byte[]
Gets an array of the bytes in a file that is specified by using a FileUpload control.
获取通过使用FileUpload控件指定的文件中字节的数组。
FileUpload fileUpload = new FileUpload();
Byte[] fileBytes = fileUpload.FileBytes;
The FileUpload control does not automatically read the file from the client.
FileUpload控件不会自动从客户端读取文件。 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.
您编写的用于保存指定文件的代码可以调用FileBytes属性,该属性返回文件的内容。
instead of FileUploadControl.FileContent
you must use FileUploadControl.FileBytes
而不是
FileUploadControl.FileContent
必须使用FileUploadControl.FileBytes
Filecontent
gives you you the stream, so either convert the stream into bytes or directly use FileBytes
Filecontent
为您提供流,因此可以将流转换为字节或直接使用FileBytes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.