rename file on upload

S

Simon

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.FileName)
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
 
P

Patrice

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top