views:

608

answers:

1

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

+6  A: 

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)

MPritch