Reputation: 1714
I want to have my Worker Role (have not done this with a web role) upload a file when it is deployed and also be able to access that deployed file in code.
How do I deploy a file with my Cloud Service to each instance?
How can I find that file in code?
Upvotes: 2
Views: 351
Reputation: 1714
Good question, Adam. To deploy a file with your cloud service you can follow this article. The 2 main points are as follows:
With these two properties set the file and its folder structure will be copied to your instance deployment. Things brings us to accessing that file in code.
To access it in code simply do the following which I got from here:
string appRoot = Environment.GetEnvironmentVariable("RoleRoot");
string pathToFiles = Path.Combine(appRoot + @"\", @"approot\" + "anyFolderNameIUsed\");
It is important to remember that this is part of the deployment package which means this file will be overwritten whenever the deployment is completed again. Also, each instance will have it's own version of the file.
If you need persistance or the ability to share file contents between your worker roles you can save your files in Blob Storage. The following article can you help accomplish this.
Upvotes: 2