Here is something simple and straightforward:
On the client side:
<INPUT id="File1" type="file" runat="server" name="FileUpload">
<asp:button id="btnUpload" runat="server"></asp:button>
On the Server:
// these will be added automatically if you are using Visual Studio
protected System.Web.UI.WebControls.Button btnUpload;
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.WebControls.Label lblReply;
this.btnUpload.Click += new System.EventHandler(this.btnUpload_Click);
// end of automatically added lines
// this function assumes InQueue is defined
private void btnUpload_Click(object sender, System.EventArgs e) {
if (File1.PostedFile.FileName == "") {
lblReply.Text = "You must specify the file first.";
} else {
string procID = DateTime.Now.ToString("MMddHHmm");
string filename = InQueue + "NewUsers." + procID + ".xls";
try {
if (File.Exists(filename)) {
lblReply.Text = "File already exists";
} else {
File1.PostedFile.SaveAs (filename);
lblReply.Text = "File " + filename + " has been received.";
}
} catch (Exception err) {
lblReply.Text = err.Message;
}
}
}