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);
}
}