<commit_before># Get started with Azure Data Lake using the .NET SDK 

Learn how to use the Azure Data Lake .NET SDK and perform common operations.  

## Prerequisites

This guide assumes you have previously followed the steps in the main [Getting Started guide](../GettingStarted.md) and the [SDK First Steps guide](FirstSteps.md).

## 01 - Namespace declations
In order to programatically access Azure Data Lake, add the following namespace declarations:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Security;
    
    using Microsoft.Azure;
    using Microsoft.Azure.Common.Authentication;
    using Microsoft.Azure.Common.Authentication.Models;
    using Microsoft.Azure.Common.Authentication.Factories;
    using Microsoft.Azure.Management.DataLake;
    using Microsoft.Azure.Management.DataLake.Models;
    using Microsoft.Azure.Management.DataLakeFileSystem;
    using Microsoft.Azure.Management.DataLakeFileSystem.Models;
    using Microsoft.Azure.Management.DataLakeFileSystem.Uploading;
    using Microsoft.IdentityModel.Clients.ActiveDirectory;

## 02 - Create a Data Lake client

There are two main clients:
* DataLakeManagementClient: allows you to manage account operations such as creating, deleting, or updating properties
* DataLakeFileSystemClient: allows you to browse, create, and delete files

To create any Data Lake client you need to provide your Azure credentials via a CloudCredentials object.  Here is an example application that creates two Data Lake clients.

    namespace DataLakeConsoleApp
    {
        class DataLakeConsoleApp
        {
          private static DataLakeManagementClient _dataLakeClient;
          private static DataLakeFileSystemManagementClient _dataLakeFileSystemClient;
          
	        static void Main(string[] args)
	        {
		    var subscriptionId = new Guid("<subID>");
		    var _credentials = GetAccessToken();

		    _credentials = GetCloudCredentials(_credentials, subscriptionId);
		    _dataLakeClient = new DataLakeManagementClient(_credentials);
		    _dataLakeFileSystemClient = new DataLakeFileSystemManagementClient(_credentials);
		}
   

        public static SubscriptionCloudCredentials GetAccessToken(string username = null, SecureString password = null)
        {
            var authFactory = new AuthenticationFactory();

            var account = new AzureAccount { Type = AzureAccount.AccountType.User };

            if (username != null && password != null)
                account.Id = username;

            var env = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
            return new TokenCloudCredentials(authFactory.Authenticate(account, env, AuthenticationFactory.CommonAdTenant, password, ShowDialog.Auto).AccessToken);
        }

        public static SubscriptionCloudCredentials GetCloudCredentials(SubscriptionCloudCredentials creds, Guid subId)
        {
            return new TokenCloudCredentials(subId.ToString(), ((TokenCloudCredentials)creds).Token);
        }

      }
   }

## 03 - Example Operations Using the Data Lake Clients 

### Create and/or Delete an Azure Data Lake account

In the Main() function above add the following lines:

	var parameters = new DataLakeAccountCreateOrUpdateParameters();
	parameters.DataLakeAccount = new DataLakeAccount
	{
		Name = "<accountName>",
		Location = "<Azure Region>"
	};
	
	_dataLakeClient.DataLakeAccount.Create("<resourceGroupName>", parameters);
	_dataLakeClient.DataLakeAccount.Delete("<resourceGroupName>", parameters);

### FileSystem Operations

A completed tutorial can be downloaded [here](src/) that will demonstrate how to perform common scenarios such as uploading, downloading, and browsing your files.
            
##### Uploading or Appending to Files

        public static bool UploadFile(DataLakeFileSystemManagementClient dataLakeFileSystemClient, string dlAccountName, string srcPath, string destPath, bool force = false)<commit_msg>Update Tutorials.md<commit_after># Get started with Azure Data Lake using the .NET SDK 

Learn how to use the Azure Data Lake .NET SDK and perform common operations.  

## Prerequisites

This guide assumes you have previously followed the steps in the main [Getting Started guide](../GettingStarted.md) and the [SDK First Steps guide](FirstSteps.md).

## 01 - Namespace declations
In order to programatically access Azure Data Lake, add the following namespace declarations:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Security;
    
    using Microsoft.Azure;
    using Microsoft.Azure.Common.Authentication;
    using Microsoft.Azure.Common.Authentication.Models;
    using Microsoft.Azure.Common.Authentication.Factories;
    using Microsoft.Azure.Management.DataLake;
    using Microsoft.Azure.Management.DataLake.Models;
    using Microsoft.Azure.Management.DataLakeFileSystem;
    using Microsoft.Azure.Management.DataLakeFileSystem.Models;
    using Microsoft.Azure.Management.DataLakeFileSystem.Uploading;
    using Microsoft.IdentityModel.Clients.ActiveDirectory;

## 02 - Create a Data Lake client

There are two main clients:
* DataLakeManagementClient: allows you to manage account operations such as creating, deleting, or updating properties
* DataLakeFileSystemClient: allows you to browse, create, and delete files

To create any Data Lake client you need to provide your Azure credentials via a CloudCredentials object.  Here is an example application that creates two Data Lake clients.

    namespace DataLakeConsoleApp
    {
        class DataLakeConsoleApp
        {
          private static DataLakeManagementClient _dataLakeClient;
          private static DataLakeFileSystemManagementClient _dataLakeFileSystemClient;
          
	        static void Main(string[] args)
	        {
		    var subscriptionId = new Guid("<subID>");
		    var _credentials = GetAccessToken();

		    _credentials = GetCloudCredentials(_credentials, subscriptionId);
		    _dataLakeClient = new DataLakeManagementClient(_credentials);
		    _dataLakeFileSystemClient = new DataLakeFileSystemManagementClient(_credentials);
		}
   

        public static SubscriptionCloudCredentials GetAccessToken(string username = null, SecureString password = null)
        {
            var authFactory = new AuthenticationFactory();

            var account = new AzureAccount { Type = AzureAccount.AccountType.User };

            if (username != null && password != null)
                account.Id = username;

            var env = AzureEnvironment.PublicEnvironments[EnvironmentName.AzureCloud];
            return new TokenCloudCredentials(authFactory.Authenticate(account, env, AuthenticationFactory.CommonAdTenant, password, ShowDialog.Auto).AccessToken);
        }

        public static SubscriptionCloudCredentials GetCloudCredentials(SubscriptionCloudCredentials creds, Guid subId)
        {
            return new TokenCloudCredentials(subId.ToString(), ((TokenCloudCredentials)creds).Token);
        }

      }
   }

## 03 - Example Operations Using the Data Lake Clients 

### Create and/or Delete an Azure Data Lake account

In the Main() function above add the following lines:

	var parameters = new DataLakeAccountCreateOrUpdateParameters();
	parameters.DataLakeAccount = new DataLakeAccount
	{
		Name = "<accountName>",
		Location = "<Azure Region>"
	};
	
	_dataLakeClient.DataLakeAccount.Create("<resourceGroupName>", parameters);
	_dataLakeClient.DataLakeAccount.Delete("<resourceGroupName>", parameters);

### FileSystem Operations

A completed tutorial can be downloaded [here](src/) that will demonstrate how to perform common scenarios such as uploading, downloading, and browsing your files.

The file system client expects local paths to be given like the following, C:\\\folder\\\test.tsv and ADL paths to be given relative to the root directory (e.g. /thisFolder/foo.txt).
            
##### Uploading or Appending to Files

        public static bool UploadFile(DataLakeFileSystemManagementClient dataLakeFileSystemClient, string dlAccountName, string srcPath, string destPath, bool force = false)
{'fraction_non_alphanumeric': 0.06823130897653036, 'fraction_numerical': 0.0014517299782240503, 'mean_word_length': 3.891715976331361, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1032071', 'n_tokens_mistral': 2090, 'n_tokens_neox': 1994, 'n_words': 669}