Last post Aug 27, 2019 06:58 PM by mgebhard
Aug 26, 2019 09:16 PM|learning_to_code|LINK
I have a beginner question on the physical path of a file.
The files are in the app_Data folder. The first line of code works AND that path is fully resolved.
How can I have a relative path that will work?
FULL PHYSICAL PATH (Resolves and loads the object correctly).
JsonSource = new UriJsonSource(new Uri(@"C:\source\repos\DevExtremeWebApp\DevXWebDoc\App_Data\FirstInvHeaderwithDetail.json"))
RELATIVE PATH 1 (Doesn't resolve and throws a runtime error.
JsonSource = new UriJsonSource(new Uri(@"\App_Data\SecondInvHeaderwithDetail.json"))
RELATIVE PATH 2 (Doesn't resolve and throws a runtime error. Notice the ~ sign.
JsonSource = new UriJsonSource(new Uri(@"~\App_Data\SecondInvHeaderwithDetail.json"))
Aug 26, 2019 11:57 PM|bruce (sqlwork.com)|LINK
Aug 27, 2019 06:43 PM|learning_to_code|LINK
So what happens when I deploy this to Azure? How will the path resolve, if a relative path doesn't work?
Aug 27, 2019 06:58 PM|mgebhard|LINK
I'm not sure where you are getting the relative path doesn't work. Your code is trying to access a physical path. The physical path of your web application files can be stored anywhere on the physical media. When you configure your hosted app, you tell
the host where to find the physical applcation files on disk.
To get the physical path, the syntax is...
string path = HttpContext.Current.Server.MapPath("~/App_Data/FirstInvHeaderwithDetail.json");
The tilde resolves to the hosted application root to the physical location. This approach will work everywhere in your app.