UploadFile control - get data
How to get data (read file) chosen in FileUpload control without FileUpload.SaveAs Met开发者_如何学Pythonhod
on the server? Is it possible write it at once to some object?
Using FileUpload.FileContent
gives you a Stream
to work with.
See MSDN.
For example:
void WriteFileLength()
{
if (fileUpload.HasFile)
{
var fileStream = fileUpload.FileContent;
var messageFormat = "The file is {0} bytes in length"
Response.Write(string.Format(messageFormat, fileStream.Length));
}
}
You have access to the byte[] of the upload by using
FileUpload1.FileBytes
where FileUpload1 is the control.
精彩评论