473,385 Members | 1,655 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,385 software developers and data experts.

rename file on upload

I'm following microsoft's guide on how to upload files. I want to upload
AND rename the file... Anyone have some tips for how to do that? Thanks

---[vb.net code]---

If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0
Then

Dim fn As String =
System.IO.Path.GetFileName(File1.PostedFile.FileNa me)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
Try
File1.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If

End Sub


Nov 19 '05 #1
2 2607
Just use whatever name you prefer for the SaveAs method. For now you are
using a string that uses the name of the posted file but this can easily be
changed...
--

"Simon" <sb**@leupold.com> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
I'm following microsoft's guide on how to upload files. I want to upload
AND rename the file... Anyone have some tips for how to do that? Thanks

---[vb.net code]---

If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0
Then

Dim fn As String =
System.IO.Path.GetFileName(File1.PostedFile.FileNa me)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
Try
File1.PostedFile.SaveAs(SaveLocation)
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Else
Response.Write("Please select a file to upload.")
End If

End Sub

Nov 19 '05 #2
> File1.PostedFile.SaveAs(SaveLocation)

uhh... see how that save function takes a parameter called filename?
How 'bout changing that?

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/

---
Get your own Travel Blog, with itinerary maps and photos!
http://www.blogabond.com/

Nov 19 '05 #3

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

Similar topics

7
by: smilesinblues | last post by:
Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to do that: $uploaddir = 'admin/'; $uploadfile = $uploaddir . basename($_FILES);...
2
by: smilesinblues | last post by:
Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to do that: $uploaddir = 'admin/'; $uploadfile = $uploaddir . basename($_FILES);...
3
by: Willem van Isselmuden | last post by:
Hello, i have this upload script, works fine, ik kan upload multiple files to my server, but i want them to be saved under a different namen on the server. My form has 4 file fields and i want...
4
by: Dynamo | last post by:
I am trying to upload a file and then rename the file as something else. Everything worked fine unless the renamed filename already existed. So I added some extra code to check if the filename...
1
by: hardik | last post by:
can anyone tell me how i can change the filename which is going to uploaded here is a code for uploading a file <!-- #include file="clsUpload.asp" --> Set objUpload = New clsUpload If...
3
by: gsoguerrilla | last post by:
Hi, I have limited knowledge in php and I am having trouble with uploading an image to a remote directory and resizing it if it's larger and renaming it to a unique id, while at the same time I...
1
by: ogo796 | last post by:
hi everyone i upload files everyday to the server using a php coded program , it works from other computers but not on the others. Could this be a problem with http headers of specific computers...
4
by: PHPstarter | last post by:
Hi guys. I'm having a problem with this case. I want a php script activated by a standard file submit to: 1) upload the file to ../../upload 2) copy the file to a directory further back, for...
1
by: achotto | last post by:
hi, i try to upload a multiple image files. after that i will rename the files name. the problem is when i upload a 2 or more same files name exp-goal.jpg, it will return "files already exist". ok...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.