title: Writing and Reading to Local Storage in Azure WebJobs
body: <p>I need to use local storage in an Azure WebJob (continuous if it matters). What is the recommended path for this? I want this to be as long-lasting as possible, so I am not wanting a Temp directory. I am well aware local storage in azure will always need to be backed by Blob storage or otherwise, which I already will be handling. </p>
  
  <p>(To preempt question on that last part: This is a not frequently changing but large file (changes maybe once per week) that I want to cache in local storage for much faster times on startup. When not there or if out of date (which I will handle checking), it will download from the source blob and so forth.)</p>
  
  <p>Related questions like <a href="https://stackoverflow.com/questions/11675343/accessing-local-storage-in-azure">Accessing Local Storage in azure</a> don't specifically apply to a WebJob. However, <a href="https://stackoverflow.com/questions/20615289/where-to-save-extract-files-on-azure-web-sites">this question</a> is vitally connected, but 1) the answer replies on using <code>Server.MapPath</code> which is a System.Web dependent solution I think, and 2) I don't find this answer to have any research or definitive basis (though it is probably a good guess for the best solution). It would be nice if the Azure team gave more direction on this important issue, we're talking about nothing less than usage of the local hard drive. </p>
  
  <p>Here are some Environment variables worth considering, though I don't know which to use:</p>
  
  <pre><code>Environment.CurrentDirectory: D:\local\Temp\jobs\continuous\webjobname123\idididid.id0
  
  [PUBLIC, D:\Users\Public]
  [ALLUSERSPROFILE, D:\local\ProgramData]
  [LOCALAPPDATA, D:\local\LocalAppData]
  [ProgramData, D:\local\ProgramData]
  [WEBJOBS_PATH, D:\local\Temp\jobs\continuous\webjobname123\idididid.id0]
  [SystemDrive, D:]
  [LOCAL_EXPANDED, C:\DWASFiles\Sites\#1appservicename123]
  [WEBSITE_SITE_NAME, webjobname123]
  [USERPROFILE, D:\local\UserProfile]
  [USERNAME, RD00333D444333$]
  [WEBSITE_OWNER_NAME, asdf1234-asdf-1234-asdf-1234asdf1234+eastuswebspace]
  [APP_POOL_CONFIG, C:\DWASFiles\Sites\#1appservicename123\Config\applicationhost.config]
  [WEBJOBS_NAME, webjobname123]
  [APPSETTING_WEBSITE_SITE_NAME, webjobname123]
  [WEBROOT_PATH, D:\home\site\wwwroot]
  [TMP, D:\local\Temp]
  [COMPUTERNAME, RD00333D444333]
  [HOME_EXPANDED, C:\DWASFiles\Sites\#1appservicename123\VirtualDirectory0]
  [APPDATA, D:\local\AppData]
  [WEBSITE_INSTANCE_ID, asdf1234asdf134asdf1234asdf1234asdf1234asdf1234asdf12345asdf12342]
  [HOMEPATH, \home]
  [WEBJOBS_SHUTDOWN_FILE, D:\local\Temp\JobsShutdown\continuous\webjobname123\asdf1234.pfs]
  [WEBJOBS_DATA_PATH, D:\home\data\jobs\continuous\webjobname123]
  [HOME, D:\home]
  [TEMP, D:\local\Temp]
  </code></pre>