Azure Web Job writes files in a website's directory

Miroslav Popov picture Miroslav Popov · Jun 11, 2014 · Viewed 13k times · Source

I attached a Web Job to my Azure website. The webjob prepares a file and I want to save it on a proper folder in the website.

Environment.CurrentDirectory run on the script returns a path under a Temp directory: Temp\jobs\triggered\WEBJOBNAME\q0uwrohv.x5e

I tried to go down on the directory tree:

string path = Path.Combine(Environment.CurrentDirectory, @"..\..\..\..\..\Data")

But it doesn't work:

C:\DWASFiles\Sites\WEBSITENAME\Temp\jobs\triggered\WEBJOBNAME\q0uwrohv.x5e\..\..\..\..\..\Data

How to make and save files from WebJob to a particular path?

I don't want to use blob store.

Answer

Amit Apple picture Amit Apple · Jun 12, 2014

The path for the root of your Azure Web Site is (usually) d:\home\site\wwwroot. d:\home is also stored in an environment setting called %HOME%.

To get more insight on the different paths you can use on your site go to: https://{sitename}.scm.azurewebsites.net, there' you'll have the Debug Console where you can browse through your site and Environment to see all the environment variables you can use.

Your WebJob will have access to the same paths/environment as your Web Site.

For more information on this administration site go to: http://azure.microsoft.com/blog/2014/03/28/windows-azure-websites-online-tools-you-should-know-about-2/