llopx

能跟您分享知识,是我的荣幸

Uploading Multiple Images from one form

Uploading Multiple Images from one form 

In ASP.NET I usually use the following code to upload multiple images:

  protected void Button1_Click(object sender, EventArgs e)
    {
        HttpFileCollection fc = Request.Files;

        for (int i = 0; i < fc.Count; i++)
        {
            HttpPostedFile hpf = fc[i];
            hpf.SaveAs("D:\\" + System.IO .Path .GetFileName(hpf.FileName));
        }
    }

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UploadMultipleImages.aspx.cs" Inherits="UploadMultipleImages" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:FileUpload ID="FileUpload3" runat="server" />&nbsp;
        <asp:FileUpload ID="FileUpload2" runat="server" />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
        <asp:FileUpload ID="FileUpload4" runat="server" /></div>
    </form>
</body>
</html>

posted on 2011-06-22 04:40  llopx  阅读(184)  评论(0编辑  收藏  举报

导航