rename file on upload

  • Thread starter Thread starter Simon
  • Start date Start date
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
 
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...
 
Back
Top