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;
}
}
}
"UJ" <fr**@nowhere.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
How can I add a browse button to my asp.net page? What I need is a button
they can press that will then let them select the file to upload to the
server.
And if anybody has any good code on how to upload a file to the server I'd
appreciate that also.
TIA - Jeffrey.