0
votes

I want to delete a specific file in the Azure Data Lake Store using .Net SDK

Used the Below code and it returns the error "Operation returned an invalid status code 'BadRequest'"

var clientCredential = new ClientCredential(CLIENTID, CLIENTSECRET);

var creds = ApplicationTokenProvider.LoginSilentAsync(DOMAINNAME, clientCredential).Result;

_adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);

var fileDeleteResult = _adlsFileSystemClient.FileSystem.Delete(_adlsAccountName, path);

1

1 Answers

1
votes

I used to get this error, which I ended up solving by using the asynchronous methods instead of the synchronous methods.

You might also want to check the file path which you are passing to the "Delete" function; it has to be the whole path, including file name + extension. Something like "/rootFolder/subFolder1/subFolder2/DeleteMe.txt"

Try something like this:

    private ServiceClientCredentials Authenticate(string _adlsDomain, string _adlsWebClientId, string _adlsClientSecret)
{               
    SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

    /*_adlsDomain       ==> DirectoryID or TenantID
      _adlsWebClientId  ==> Application ID
      _adlsClientSecret ==> Active Directory APplication key1
    */

    ClientCredential clientCredential = new ClientCredential(_adlsWebClientId, _adlsClientSecret);

    return ApplicationTokenProvider.LoginSilentAsync(_adlsDomain, clientCredential).Result;     

}

private async Task DeleteFile(string path)
{
    string _adlsDomain = "xxxx";
    string _adlsWebClientId = "xxxx";
    string _adlsClientSecret = "xxxx";      
    string _subscription_id = "xxxx";
    string _adlsAccountName = "xxxxxxx";
    ServiceClientCredentials _creds = Authenticate(_adlsDomain, _adlsWebClientId, _adlsClientSecret)

    // Create client objects and set the subscription ID
    DataLakeStoreAccountManagementClient _adlsClient = new DataLakeStoreAccountManagementClient(_creds) { SubscriptionId = _subscription_id };
    DataLakeStoreFileSystemManagementClient _adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(_creds);

    await _adlsFileSystemClient.FileSystem.DeleteAsync(_adlsAccountName, path);
}