473,383 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Browse for a filename?

UJ
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.
Nov 19 '05 #1
3 1809
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.

Nov 19 '05 #2
UJ
That's perfect. Thanks!

"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
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.


Nov 19 '05 #3
UJ
Bob,
That does work great. But is there any way to have more control over it? For
instance our buttons look different and I'd like to have the button below
the field instead of next to id.

Thanks again.

"UJ" <fr**@nowhere.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
That's perfect. Thanks!

"Bob Weiner" <bo*@engr.uconn.edu> wrote in message
news:O$**************@TK2MSFTNGP15.phx.gbl...
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.



Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jane Doe | last post by:
Hi, I need to add a download function in a VB program, but since a file can be located anywhere in our /download section on the web, I was thinking of putting a PHP script there that would take...
21
by: strutsng | last post by:
<input type="file"> only allows the user to browse for files. How about "browse for folder" dialog? Can html/javascript do that? I couldn't find any syntax for that. If not, please advise what...
5
by: Rob | last post by:
Help me, I'm just beginning with programming in Access 2000. I've tried the http://www.mvps.org/access/api/api0001.htm but it won't work in Access. What am i doing wrong. I don't have...
5
by: Joe Bloggs | last post by:
I have an Oracle database that holds a Blob field containing a PDF report. I've been researching into if its possible to implement a Brose for folder functionality in a web page so to allow a user...
5
by: Dan | last post by:
I am working on a C# ASP.NET project where I need to allow the user to browse to a folder. The only way I see how to do this is use <input type=file>. But this makes the user select a file and...
3
by: Wardeaux | last post by:
Hey all, need sample/article how to let user browse local drives to select a file and have the local drive location returned so I can store it in my db, similar to a file upload but without the...
5
by: Mike Moore | last post by:
I need to create something very similiar to the browse folder capability. This would allow me to support the following - A user would create a document on their server, then they would need to...
1
by: Bob | last post by:
Greetings! I need to use the windows browse dialog to select and store a fileaname. I can get the filename with the path no problem. But I ONLY want to return the filename. Does anyone...
3
by: Bob | last post by:
Greetings! I need to use the windows browse dialog to select and store a fileaname. I can get the filename with the path no problem. But I ONLY want to return the filename. Does anyone...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.