Use the HtmlInputFile control. : File upload « HTML Controls « ASP.NET Tutorial






<%@ Page language="C#"%>
<%@ Import Namespace="System.IO" %>

<script runat="server">
    void UploadButton_Click(object sender, EventArgs e)
    {
        string savePath = @"c:\";
        if (!Directory.Exists(savePath)) {
          string msg = "<h1>The upload path doesn't exist: {0}</h1>";
            Response.Write(String.Format(msg, savePath));
            Response.End();
        }
        if (FileUpload1.PostedFile != null)
        {
            string fileName = Path.GetFileName(FileUpload1.Value);

            savePath += fileName;

          FileUpload1.PostedFile.SaveAs(savePath);
            UploadStatusLabel.InnerText = "File saved as: <i>" + savePath + "</i>";
        }
        else
        {
            UploadStatusLabel.InnerText = "You did not specify a file to upload.";
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>HtmlInputFile</title>
</head>
<body>
    <div id="pageContent">

        <form ID="Form1" runat="server">
          <h3>Select a picture to upload:</h3>
            <hr />
            <b>Picture to upload</b><br />
            <input type="file" id="FileUpload1" runat="server" />
            <br /><br />
            <input runat="server" id="UploadButton" type="submit" value="Upload" 
                onserverclick="UploadButton_Click" />
            <hr />
           <span runat="server" id="UploadStatusLabel" />
       </form>
    </div>
</body>
</html>








4.4.File upload
4.4.1.Use the HtmlInputFile control.
4.4.2.input type='file'
4.4.3.PostedFile.SaveAs