Upload file to server

Maddy40

Member
Joined
Sep 15, 2005
Messages
9
Programming Experience
1-3
Ok this code works if save location is server.mapPath but as you can see
i want to save on a different location the error is
"Error: URI formats are not supported" not sure where i am going wrong any ideas?

VB.NET:
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
  Dim SaveLocation As String = "http:\\maca\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
 
Last edited by a moderator:
You are using an Http: address when you should be pointing to the actual folder such as C:\....

Make Server.MapPath("data").tostring in a label or somthing and you will see what the location looks like. I don't believe it's using an address like your specifying but an actual folder like C:\Website\data\....
 
Also it is good practive to use that Path.Combine() function. here is an example.

VB.NET:
this code you had above...
'Dim SaveLocation As String = Server.MapPath("Data") & " \ " & fn
 
'it could read.
'Dim SaveLocation as String = Path.Combine(Server.MapPath("Data"), fn)

The Path.Combine feature will insure the "\" is always correct incase you don't know if you already have one on the Server.MapPath or the fn or in between. I preffer to let the Path.Combine function keep up with this for me.
 
Since this is related to file upload. I used simular code to ImDaFreak. Only thing I can complain about is the user does not really know the status of the upload while the upload is in progress. Any snipets for such a jewel in VB.NET? I saw one for C# but didnt know how to convert it to my application.
 
Back
Top