It is common to need to access files as resources from local disk from within a .NET service or user interface. Apprenda will decide where to deploy your services and user interfaces, however, so it is not possible to rely on traditional absolute and relative path structures.
Apprenda provides a special configuration token to assist in locating these resources from within your application. The value of the token will be substituted with the appropriate value when the site or service is deployed or moved on the grid. The following example illustrates how to and how not to reference a static file from your UI or service:
Using Apprenda Scripting Variables
<appSettings> <!—- Absolute Path Invalid When Deployed to Apprenda --> <add key="myResourceFile" value="C:\MyDirectory\MyResourceFile.xml"/> <!—- Relative Path Invalid When Deployed to Apprenda --> <add key="myResourceFile" value="MyResourceFile.xml"/> <!—- Scripted Path Valid When Deployed to Apprenda --> <add key="myResourceFile" value="$#BASEPATH#$\MyResourceFile.xml"/> </appSettings>
In addition to the $#BASEPATH#$ token, there are several other tokens that are detected at deployment time that can be used in the application’s configuration file. Additionally, Apprenda’s conditional configuration system allows you to configure your application to reference a different application path while running the application locally. Refer to the Conditional App Configuration and Tokens section for additional information.
Because user interfaces and services are stateless by the nature of Apprenda’s deployment mechanics, file access may only be used for read-only scenarios. Updating or appending the target file will not propagate across multiple instances of a .NET service, so there is no deterministic behavior that can be expected when updating a file.