0
    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のImageControlに画像を表示するにはどうすればよいですか?

ありがとう

4

1 に答える 1

3
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);
        }
}
于 2013-02-04T10:04:52.590 に答える