473,668 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1822
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.

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

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


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.c om> wrote in message
news:eZ******** ******@TK2MSFTN GP09.phx.gbl...
That's perfect. Thanks!

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



Nov 19 '05 #4

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

Similar topics

6
11194
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 the filename as parameter, and browse through the /download directory to look for this file, including sub-directories, and return the URL, ie. IN http://www.acme.com/download/find.php?file=myfile.txt
21
66815
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 are the other approaches. please advise. thanks!!
5
2967
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 problems with the http://www.mvps.org/access/api/api0002.htm but it only browse to folders.
5
20591
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 to specify a folder to download the PDF to. The only way I can think of doing this at the moment is to first download the report to the Webserver and then have a link on the web page to the location of the downloaded report and then the user...
5
3222
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 returns folder + filename. I only want the folder path. Does someone have a possible solution other than <input type=file>?
3
2234
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 actual file transfer and I need the full path... any assist is greatly appreciated!! MTIA wardeaux
5
3130
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 login to the application which we are building to 1). the user would locate their purchase request record in the application. 2). browse the directory for the newly created document 3). find it 4). they would click a save button - this would...
1
1160
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 know how I can just return the filename?
3
2009
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 know how I can just return the filename?
0
8381
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8656
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7401
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6209
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5681
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4205
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2791
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1786
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.