【问题标题】:Converting HttpFileCollection to byte and stream the data to Image Control in asp.net将 HttpFileCollection 转换为字节并将数据流式传输到 asp.net 中的图像控件
【发布时间】:2013-01-18 21:59:57
【问题描述】:
    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 中的 Image Control

谢谢

【问题讨论】:

    标签: asp.net byte httpfilecollection


    【解决方案1】:
    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);
            }
    }
    

    【讨论】:

      猜你喜欢
      • 2010-11-23
      • 2016-08-11
      • 2015-10-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      相关资源
      最近更新 更多