将HttpFileCollection转换为字节,并将数据流式传输到asp.net中的图像控制


    HttpFileCollection oHttpFileCollection = e.PostedFiles;
    HttpPostedFile oHttpPostedFile = null;
    if (e.HasFiles)
    {
        for (int n = 0; n < e.Count; n++)
        {
            oHttpPostedFile = oHttpFileCollection[n];
            if (oHttpPostedFile.ContentLength <= 0)
                continue;
            else
                oHttpPostedFile.SaveAs(Server.MapPath("Files") + "\" + System.IO.Path.GetFileName(oHttpPostedFile.FileName));
    }

如何将HttpFileCollection转换为字节并读取流,然后在asp.net 中将图像显示给图像控制

感谢

HttpFileCollection oHttpFileCollection = e.PostedFiles;
HttpPostedFile oHttpPostedFile = null;
if (e.HasFiles)
{
    for (int n = 0; n < e.Count; n++)
    {
        oHttpPostedFile = oHttpFileCollection[n];
        if (oHttpPostedFile.ContentLength <= 0)
        {
            continue;
        }
        else
        {
            var filename = Path.GetFileName(oHttpPostedFile.FileName);
            var path = Path.Combine(Server.MapPath("~/Files/"), filename);
            oHttpPostedFile.SaveAs(path);
            // Now you could display each image in a dynamically added Image
            // control to the page:
            Image image = new Image();
            image.ImageUrl = "~/Files/" + filename;
            // I assume that you have a reference to the current page
            // so that you could append image controls to it.
            // You could also append the images to a placeholder or a Panel
            // on your WebForm
            this.Controls.Add(image);
        }
}

相关内容

  • 没有找到相关文章

最新更新