Friday, July 20, 2018

c# asp.net - simple aspx file to upload a file to server

Save below as an .aspx file in IIS.

<%@ Page Language="C#" AutoEventWireup="true" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test Upload file</title>
</head>
<body>
<form id="form1" runat="server" enctype="multipart/form-data">
 <input type="file" id="myFile" name="myFile" />
 <asp:Button runat="server"
   ID="btnUpload" OnClick="btnUploadClick" Text="Upload" />
</form>
<script runat=server>
protected void btnUploadClick(object sender, EventArgs e)
{
    HttpPostedFile file = Request.Files["myFile"];

    //check file was submitted
    if (file != null && file.ContentLength > 0)
    {
        string fname = System.IO.Path.GetFileName(file.FileName);
        file.SaveAs((System.IO.Path.Combine("C:/Temp/", fname)));
    }
}
</script>
</body>
</html>

No comments:

Turn on Windows 11 Fast Boot

If windows starting is slow, to enable windows 11 fast startup/boot,  Press Windows + R, type powercfg.cpl, and hit Enter.  This will direct...