473,404 Members | 2,178 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,404 software developers and data experts.

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="text/html" ResponseEncoding="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_OnClick( Object o, EventArgs e )
{
fileUpload.PostedFile.SaveAs(Server.MapPath("test. txt") );
}
</script>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
<input name="fileUpload" type="file" id="fileUpload" runat="server">
<asp:button ID="btnUploadFile" runat="server" Text="Upload File"
OnClick="btnUploadFile_OnClick" />
</form>
</body>
</html>

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

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

fileUpload.PostedFile.SaveAs(Server.MapPath("test. txt") );

Something like this should work:
string fileName =
System.IO.Path.GetFileName(fileUpload.PostedFile.F ileName);
fileUpload.PostedFile.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****@excalibur.force8.net> wrote in message
news:wP********************@pipex.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="text/html"
ResponseEncoding="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_OnClick( Object o, EventArgs e )
{
fileUpload.PostedFile.SaveAs(Server.MapPath("test. txt") );
}
</script>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
<input name="fileUpload" type="file" id="fileUpload" runat="server">
<asp:button ID="btnUploadFile" runat="server" Text="Upload File"
OnClick="btnUploadFile_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_OnClick( Object o, EventArgs e )
{
string filename=
System.IO.Path.GetFileName(fileUpload.PostedFile.F ilename);
fileUpload.PostedFile.SaveAs("Server.MapPath(".") "\\" + fileName);
}

</script>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
<input name="fileUpload" type="file" id="fileUpload" runat="server">
<asp:button ID="btnUploadFile" runat="server" Text="Upload File"
OnClick="btnUploadFile_OnClick" />
</form>
</body>
</html>
Nov 19 '05 #3
System.IO.Path.GetFileName(fileUpload.PostedFile.F ilename);
fileUpload.PostedFile.SaveAs(REMOVE_THE_DOUBLE_QUO TE_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****@excalibur.force8.net> wrote in message
news:fY********************@pipex.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_OnClick( Object o, EventArgs e )
{
string filename=
System.IO.Path.GetFileName(fileUpload.PostedFile.F ilename);
fileUpload.PostedFile.SaveAs("Server.MapPath(".") "\\" + fileName);
}

</script>
</head>
<body>
<form runat="server" enctype="multipart/form-data">
<input name="fileUpload" type="file" id="fileUpload" runat="server">
<asp:button ID="btnUploadFile" runat="server" Text="Upload File"
OnClick="btnUploadFile_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
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...
0
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...
2
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...
13
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...
1
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....
9
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...
0
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...
2
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...
2
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...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
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...
0
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...
0
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,...
0
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...

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.