Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7952
  • Last Modified:

File Upload

Hello, I'm trying to use the file upload control to let users upload a file to my hosted site. I get this error:

The SaveAs method is configured to require a rooted path, and the path 'http://www.website.com/pdf/79493233_249894425_0.jpg' is not rooted.

What would be the correct path it is expecting?

Here is my code:

  Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        If FileUpload1.HasFile Then
            FileUpload1.SaveAs("http://www.website.com/pdf/" & FileUpload1.FileName)
            lblmessage2.Text = "Received " & FileUpload1.FileName & " Content Type " & FileUpload1.PostedFile.ContentType & " Length " & FileUpload1.PostedFile.ContentLength
            lblmessage2.Text = "No uploaded file"
        End If
        lblmessage2.Visible = True

    End Sub
  • 2
  • 2
1 Solution
You need a physical path not a web path.  Try this:

FileUpload1.SaveAs(Server.MapPath("http://www.website.com/pdf/" & FileUpload1.FileName))

(Of course the syntax may be slightly different since that is for C#...)
gogetsomeAuthor Commented:
Thank you mrichmon for helping.

I converted the C# but may have gotten it wrong. I'm getting this error message:

'http://www.website.com/pdf/VBADevelopersGuide.pdf' is not a valid virtual path.

Here is my conversion:

FileUpload1.SaveAs(Server.MapPath("http://www.website.com/pdf/" & FileUpload1.FileName))

Does it have to take an FTP rather than HTTP?
At least in C# the Server.MapPath takes a web path and converts into a physical path.

However, you may need to send in only the path like this:

FileUpload1.SaveAs(Server.MapPath("http://www.website.com/pdf/") & FileUpload1.FileName)

SO the filename gets appended after the path is converted.
gogetsomeAuthor Commented:
Cool that explains it! Thank you so much

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now