473,796 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

upload code info required!

Hello there,

I'm using the below code and it works, but as usual, it does not quite give
me everything I need:

No matter what file I click on, it only ever save the file as test.txt and
that's my problem... This upload function will be used for various filetypes
and thus i need the code to take the filename of the file I am uploading,
or, somehow ask me what filename I would like!

Any ideas?

<%@ Page Language="C#" ContentType="te xt/html" ResponseEncodin g="iso-8859-1"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload </title>
<script runat="server">
void btnUploadFile_O nClick( Object o, EventArgs e )
{
fileUpload.Post edFile.SaveAs(S erver.MapPath(" test.txt") );
}
</script>
</head>
<body>
<form runat="server" enctype="multip art/form-data">
<input name="fileUploa d" type="file" id="fileUpload " runat="server">
<asp:button ID="btnUploadFi le" runat="server" Text="Upload File"
OnClick="btnUpl oadFile_OnClick " />
</form>
</body>
</html>

Nov 19 '05 #1
3 1326
How can this not be expected?

You are telling it to save as test.txt....you have "test.txt" hardcoded in
there...

fileUpload.Post edFile.SaveAs(S erver.MapPath(" test.txt") );

Something like this should work:
string fileName =
System.IO.Path. GetFileName(fil eUpload.PostedF ile.FileName);
fileUpload.Post edFile.SaveAs(" Server.MapPath( ".") "\\" + fileName);

karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Dam6" <da****@excalib ur.force8.net> wrote in message
news:wP******** ************@pi pex.net...
Hello there,

I'm using the below code and it works, but as usual, it does not quite
give me everything I need:

No matter what file I click on, it only ever save the file as test.txt and
that's my problem... This upload function will be used for various
filetypes and thus i need the code to take the filename of the file I am
uploading, or, somehow ask me what filename I would like!

Any ideas?

<%@ Page Language="C#" ContentType="te xt/html"
ResponseEncodin g="iso-8859-1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Upload </title>
<script runat="server">
void btnUploadFile_O nClick( Object o, EventArgs e )
{
fileUpload.Post edFile.SaveAs(S erver.MapPath(" test.txt") );
}
</script>
</head>
<body>
<form runat="server" enctype="multip art/form-data">
<input name="fileUploa d" type="file" id="fileUpload " runat="server">
<asp:button ID="btnUploadFi le" runat="server" Text="Upload File"
OnClick="btnUpl oadFile_OnClick " />
</form>
</body>
</html>

Nov 19 '05 #2
Thank you for the reply!

I have now added your code as follows: (With the error when ran)

Compiler Error Message: CS1010: Newline in constant

<script runat="server">
void btnUploadFile_O nClick( Object o, EventArgs e )
{
string filename=
System.IO.Path. GetFileName(fil eUpload.PostedF ile.Filename);
fileUpload.Post edFile.SaveAs(" Server.MapPath( ".") "\\" + fileName);
}

</script>
</head>
<body>
<form runat="server" enctype="multip art/form-data">
<input name="fileUploa d" type="file" id="fileUpload " runat="server">
<asp:button ID="btnUploadFi le" runat="server" Text="Upload File"
OnClick="btnUpl oadFile_OnClick " />
</form>
</body>
</html>
Nov 19 '05 #3
System.IO.Path. GetFileName(fil eUpload.PostedF ile.Filename);
fileUpload.Post edFile.SaveAs(R EMOVE_THE_DOUBL E_QUOTE_HERE
Server.MapPath( ".") "\\" + fileName);

I put an extra " in the SaveAs

anywyas, if you play with the above code you ought to get it to work

If you get stuck again, check out this straightforward article:
http://www.4guysfromrolla.com/webtech/091201-1.shtml

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Dam6" <da****@excalib ur.force8.net> wrote in message
news:fY******** ************@pi pex.net...
Thank you for the reply!

I have now added your code as follows: (With the error when ran)

Compiler Error Message: CS1010: Newline in constant

<script runat="server">
void btnUploadFile_O nClick( Object o, EventArgs e )
{
string filename=
System.IO.Path. GetFileName(fil eUpload.PostedF ile.Filename);
fileUpload.Post edFile.SaveAs(" Server.MapPath( ".") "\\" + fileName);
}

</script>
</head>
<body>
<form runat="server" enctype="multip art/form-data">
<input name="fileUploa d" type="file" id="fileUpload " runat="server">
<asp:button ID="btnUploadFi le" runat="server" Text="Upload File"
OnClick="btnUpl oadFile_OnClick " />
</form>
</body>
</html>

Nov 19 '05 #4

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

Similar topics

32
3738
by: Ray at | last post by:
I despise installing third party software on my workstations or servers. It is for this reason that I use componentless-upload for file uploads. This is no longer an option, and I have to purchase an upload component. For someone who hates third party software and also does not want any kind of nonsense "bonus" features like progress bars or whatever, can anyone recommend a component for me? The cost doesn't really matter. I am aware...
0
3209
by: Pepito Grillo | last post by:
Hi. I have an asp.net web application and I'd like to upload it to my web. I uploaded all the .aspx and .config files, so the bin folder (with the dll). But the problem is that the application does not work as it does on my computer. The code I use is: Imports System.IO Imports System.Net Public Class analize Inherits System.Web.UI.Page
2
6064
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet server. On the line: dirs = Directory.GetDirectories(currentDir) I get "Access to the path "\\les-net\les\Special Projects\ATSPDF" is denied." How do I get the GetDirectories command to user my user ID and password when it tries to hit the...
13
2359
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't reached yet (I have gone all the way to page 50 on Google's results!!). Here are my requirements: • I have a DataGrid. Everything will be done from here. Everything. No exceptions. Everything will also be done in VB, without any code-behind to...
1
2727
by: DavidA | last post by:
I have a very simple form and perl script that is to upload a jpg file. I am not familiar with the perl language but copied the code from a text book. It works fine with all browsers except IE. !!!!! The code is able to validate that it is a jpg but never gets to the debugging statement 'in loop" I have seen numerious complaints via google searches about IE and uploads but am unable to decipher the solution. Any help will be...
9
20902
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at rapidshare news : http://images.rapidshare.com/software/rsapi.pl If you test it you will see that you can upload one file at time. I try to modify it in that way that script can read a text file with the names of the files i want to...
0
9802
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted by the software in your host machine. Stack Trace at System.Net.Sockets.NetworkStream.Write(Byte buffer, Int32 offset, Int32
2
7651
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but don't have any luck is to do a form validation. This script requires the files: db-file-to-disk.asp and _upload.asp. There is a DESCRIPTION field in the db-file-to-disk.asp file, what I want to do is the user has to field out this fied before...
2
2917
by: hotflash | last post by:
Hi Master CroCrew, I found a good PURE ASP that will allow you to upload 10MB file to the server and the file contents such as Network, Author, Title, etc... will insert to MS Access at the same time. Below is a working script that I used. Let's say after the file is uploaded to the server and a record created with the file contents above to the MS Access (using the script below). If I want to UPDATE that record let's say, change the...
0
9679
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
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
10003
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...
1
7546
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
5441
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...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4115
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
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
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.