The SaveAs method is configured to require a rooted path, and the path '~\\images\\594083964.jpg' is not rooted

20,961

The path you are saving to is a relative URL. You need to save to a local file path (or full network path).

Try:

string relativePath = @"~\images\"+ i + Path.GetExtension(fu1.FileName);
fu1.SaveAs(Server.MapPath(relativePath));

(Path.GetExtension(string) will handle file extensions that aren't 3 characters too)

Share:
20,961
Admin
Author by

Admin

Updated on October 04, 2020

Comments

  • Admin
    Admin over 3 years

    The SaveAs method is configured to require a rooted path, and the path '~\images\594083964.jpg' is not rooted. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details:

    System.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path '~\images\594083964.jpg' is not rooted.

    Source Error:

    Line 27:     {
    Line 28: 
    Line 29:         fu1.SaveAs(@"~\\images\\" + i + fu1.FileName.Substring(fu1.FileName.Length - 4, 4));
    Line 30: path = "~\\images\\"+i + fu1.FileName.Substring(fu1.FileName.Length-4,4);
    Line 31: }
    

    Source File: e:\PEOPLE\Ravi\new data\WebSite1\signup.aspx.cs Line: 29

  • Guffa
    Guffa about 12 years
    Although you should use / in the relative path, not \.
  • MPritchard
    MPritchard almost 12 years
    @Guffa Are you sure that makes any difference?
  • Guffa
    Guffa almost 12 years
    The method may be nice enough to convert the incorrect separators to the correct ones, but there is no reason to rely on that behavior (that might change) when you can just as easily use the correct separators instead.