开发者

UploadFile control - get data

开发者 https://www.devze.com 2023-02-11 07:10 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消