PostedFile.SaveAs : File upload « HTML Controls « ASP.NET Tutorial






<%@ Page Language="C#" %>
<script runat="server">
void UploadButton_Click(Object sender, EventArgs e) {
    if(FileInput.PostedFile != null)
        {
            try
            {
                FileInput.PostedFile.SaveAs("c:\\test.txt");
            }
            catch (Exception exc)
            {
                Response.Write(exc.Message);
            }
        }
    }
</script>
<html>
  <head>
  </head>
  <body>
    <form id="Form1" method="post" enctype="multipart/form-data" runat="server">
        <input id="FileInput" type="file" runat="server" />
        <asp:Button id="UploadButton" onclick="UploadButton_Click" runat="server" Text="Upload"></asp:Button>
    </form>
  </body>
</html>








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