Search code examples
c#azureazure-blob-storagestorageazure-data-lake-gen2

Can we upload a file to datalake storage into a nested folder in azure with c#?


I am uploading a file to a container and it's work perfectly. but I want to upload a file to a nested particular directory.

So how can I do that with c#?


Solution

  • You can do it this way:

    DataLakeDirectoryClient directoryClient =
        fileSystemClient.GetDirectoryClient("my-directory/my-subdirectory");
    DataLakeFileClient fileClient = await directoryClient.CreateFileAsync("uploaded-file.txt");
    
    FileStream fileStream =
        File.OpenRead("C:\\Users\\contoso\\Temp\\file-to-upload.txt");
    
    long fileSize = fileStream.Length;
    
    await fileClient.AppendAsync(fileStream, offset: 0);
    
    await fileClient.FlushAsync(position: fileSize);