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

Viewed 21

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#?

1 Answers

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);
Related