Here is something simple and straightforward :
On the client side:
<INPUT id="File1" type="file" runat="server" name="FileUploa d">
<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.W ebControls.Butt on btnUpload;
protected System.Web.UI.H tmlControls.Htm lInputFile File1;
protected System.Web.UI.W ebControls.Labe l lblReply;
this.btnUpload. Click += new System.EventHan dler(this.btnUp load_Click);
// end of automatically added lines
// this function assumes InQueue is defined
private void btnUpload_Click (object sender, System.EventArg s e) {
if (File1.PostedFi le.FileName == "") {
lblReply.Text = "You must specify the file first.";
} else {
string procID = DateTime.Now.To String("MMddHHm m");
string filename = InQueue + "NewUsers." + procID + ".xls";
try {
if (File.Exists(fi lename)) {
lblReply.Text = "File already exists";
} else {
File1.PostedFil e.SaveAs (filename);
lblReply.Text = "File " + filename + " has been received.";
}
} catch (Exception err) {
lblReply.Text = err.Message;
}
}
}
"UJ" <fr**@nowhere.c om> wrote in message
news:uM******** ******@TK2MSFTN GP09.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.