title: Azure Functions - Access To Path Is Denied
body: <p>I am getting the following error when running the published version of my function, it should be noted that when I run this locally it works correctly.</p>
  
  <blockquote>
    <p>Access to the path 'D:\Program Files
    (x86)\SiteExtensions\Functions\1.0.12205\wkhtmltopdf' is denied. at
    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at
    System.IO.Directory.InternalCreateDirectory(String fullPath, String
    path, Object dirSecurityObj, Boolean checkHost) at
    System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean
    checkHost) at System.IO.Directory.CreateDirectory(String path) at
    NReco.PdfGenerator.HtmlToPdfConverter.EnsureWkHtmlLibs() at
    NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdfInternal(WkHtmlInput[]
    htmlFiles, String inputContent, String coverHtml, String
    outputPdfFilePath, Stream outputStream) at
    NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent,
    String coverHtml, Stream output) at
    NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent,
    String coverHtml) at
    NReco.PdfGenerator.HtmlToPdfConverter.GeneratePdf(String htmlContent)
    at HTMLtoPDF.Function1.d__0.MoveNext()</p>
  </blockquote>
  
  <p>My application basically transforms HTML into a PDF file, uploads to azure and returns the result uri.</p>
  
  <p>As you can see in my code below I don't make any references to this path.</p>
  
  <pre><code>using System.IO;
  using System.Linq;
  using System.Net;
  using System.Net.Http;
  using System.Threading.Tasks;
  using Microsoft.Azure.WebJobs;
  using Microsoft.Azure.WebJobs.Extensions.Http;
  using Microsoft.Azure.WebJobs.Host;
  using Microsoft.WindowsAzure.Storage;
  using Microsoft.WindowsAzure.Storage.Blob;
  using NReco.PdfGenerator;
  using System;
  
  namespace HTMLtoPDF
  {
      public static class Function1
      {
          [FunctionName("Function1")]
          public static async Task&lt;HttpResponseMessage&gt; Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
          {
              log.Info("C# HTTP trigger function processed a request.");
              string pdfurl = "";
              // parse query parameter
              string html = req.GetQueryNameValuePairs()
                  .FirstOrDefault(q =&gt; string.Compare(q.Key, "html", true) == 0)
                  .Value;
  
              if (html == null)
              {
                  // Get request body
                  dynamic data = await req.Content.ReadAsAsync&lt;object&gt;();
                  html = data?.html;
              }
              try
              {
                  HtmlToPdfConverter converter = new HtmlToPdfConverter();
                  var genpdf = converter.GeneratePdf(html);
                  var stream = new MemoryStream(genpdf, writable: false);
                   pdfurl = await UploadFileAsBlobAsync(stream, Guid.NewGuid()+".pdf");
              }
              catch (Exception ex)
              {
               pdfurl = ex.Message+Environment.NewLine+ex.InnerException;
              }
  
              return html == null
                  ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass html on the query string or in the request body")
                  : req.CreateResponse(HttpStatusCode.OK, pdfurl);
          }
          public static async Task&lt;string&gt; UploadFileAsBlobAsync(Stream stream, string filehtml)
          {
              CloudStorageAccount storageAccount = CloudStorageAccount.Parse(HIDDENFORSECURITY);
  
              // Create the blob client.
              CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
  
              // Retrieve a reference to a container.
              CloudBlobContainer container = blobClient.GetContainerReference("applicationimages");
  
              CloudBlockBlob blockBlob = container.GetBlockBlobReference(filehtml);
  
             await  blockBlob.UploadFromStreamAsync(stream);
  
              stream.Dispose();
              return blockBlob?.Uri.ToString();
  
          }
      }
  }
  </code></pre>