title: How to read and write files into azure data lake
body: <p>I need a bit of help with my azure function to be able to read and write files into data lake using C# (visual code). I do have visual studio 2019 available if needed.  </p>
  
  <p><strong>Update since I created the question</strong></p>
  
  <blockquote>
    <p>Is it possible to connect to data lake using a connection string?</p>
  </blockquote>
  
  <p><strong>Code snippet</strong></p>
  
  <pre><code>  [FunctionName("MyExampleFunction")]
          public static void Run([ServiceBusTrigger("mytopic", "mysubscription", Connection = "myservicebus")]string mySbMsg, ILogger log)
          {
              // Save file into azure data lake
          }
  </code></pre>
  
  <p>First time writing azure functions, I'm using Visual Code and C# and I'm aware of the following library but not sure how to use it.</p>
  
  <p><a href="https://github.com/Azure/azure-functions-datalake-extension/blob/master/samples/DataLakeExtensionSamples/OutputFromBlob.cs" rel="nofollow noreferrer">https://github.com/Azure/azure-functions-datalake-extension/blob/master/samples/DataLakeExtensionSamples/OutputFromBlob.cs</a></p>
  
  <p>I've come across this code whilst searching online but I'm not sure how to add the necessary extension within visual code, all my years of experience is within visual studo with nuget package manager.  I've looked at the visual code extensions panel but typing in 'service model' the extension doesn't come up..?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>private static void SaveToDataLake(string objectToSave)
          {
              var applicationId = "";
              var clientSecret = "";
              var tenantId = "";
              var adlsAccountFQDN = "";
  
              var creds = new ClientCredential(applicationId, clientSecret);
               var clientCreds = ApplicationTokenProvider.LoginSilentAsync(tenantId, creds).GetAwaiter().GetResult();
  
               AdlsClient client = AdlsClient.CreateClient(adlsAccountFQDN, clientCreds);
  
               using (var stream = client.CreateFile(fileName, IfExists.Overwrite))
               {
                   stream.Write(objectToSave, 0, objectToSave.Length);
               }
          }
  </code></pre>
  
  <p><strong>Error message in portal</strong></p>
  
  <p><a href="https://i.stack.imgur.com/OGgwd.png" rel="nofollow noreferrer">screen shot of error message received</a></p>