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

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

Exception Details:

System.Web.HttpException: the SaveAs method is configured to need a root path, and the path '~ \ images \ 594083964.jpg' is not implemented.

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

+7
c # exception
source share
1 answer

The path you save is the relative url. You need to save the path to the local file (or the 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 are not 3 characters)

+21
source share

All Articles