File Upload

Posted on 2006-05-05
Last Modified: 2011-08-18
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 '' 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("" & 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
Question by:gogetsome
    LVL 35

    Accepted Solution

    You need a physical path not a web path.  Try this:

    FileUpload1.SaveAs(Server.MapPath("" & FileUpload1.FileName))

    (Of course the syntax may be slightly different since that is for C#...)

    Author Comment

    Thank you mrichmon for helping.

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

    '' is not a valid virtual path.

    Here is my conversion:

    FileUpload1.SaveAs(Server.MapPath("" & FileUpload1.FileName))

    Does it have to take an FTP rather than HTTP?
    LVL 35

    Expert Comment

    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("") & FileUpload1.FileName)

    SO the filename gets appended after the path is converted.

    Author Comment

    Cool that explains it! Thank you so much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now