Forum Discussion
Uploading Files using .Net in C#
- 1 year ago
For now I have aboned this project since logging in using a User Id and a Passward without MFA. Is a royal pain.
- 1 year ago
Hi spartan27244,
Thanks for the confirmation, we understand your pain in this scenario. I’d encourage you to submit your detailed feedback and ideas via Microsoft's official feedback channels, such as the Microsoft Fabric Ideas. Feedback submitted here is often reviewed by the product teams and can lead to meaningful improvement.
Thanks,
Prashanth Are
MS Fabric community support
The destination folders do already exist. However I am not quite sure where the root begins. The Data Lake already creates Tables and Files folders. I am not sure when I connect to I start with "Files/Subfolder1/Subfolder2/Filename.txt" or "Subfolder1/Subfolder2/Filename.txt". I'm sure I have tried both.
could it also be the cred, I am working on a machine that is not part of the Entra domain where the lakehouse resides. I have a service Id and pwd that does not require MFA to use but I cannot figure out how to do it.
Hi spartan27244,
When you connect using a DataLakeServiceClient or DataLakeFileSystemClient, hierarchy starting at the container level (i.e., the Fabric Lakehouse’s Files or Tables container). If you're working in the Files area, you must start your path with "Files/"
"Files/Subfolder1/Subfolder2/MyFile.txt"
If you're working on a machine that’s not Entra-joined and have a service principal (client ID and secret) that doesn’t require MFA, the best option is to use the ClientSecretCredential class. This explicitly authenticates using your app registration details in Azure.
using Azure.Identity;
using Azure.Storage.Files.DataLake;
// Replace with your actual values
string tenantId = "<your-tenant-id>";
string clientId = "<your-client-id>";
string clientSecret = "<your-client-secret>";
string lakeUrl = "https://<your-storage-account-name>.dfs.core.windows.net";
// Authenticate using client credentials
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var serviceClient = new DataLakeServiceClient(new Uri(lakeUrl), credential);
// Connect to the container (Lakehouse workspace)
var fileSystemClient = serviceClient.GetFileSystemClient("my-workspace");
// Set the directory path including the logical 'Files' container
var directoryClient = fileSystemClient.GetDirectoryClient("Files/Subfolder1/Subfolder2");
await directoryClient.CreateIfNotExistsAsync();
// Upload the file
var fileClient = directoryClient.GetFileClient("MyFile.txt");
using var stream = File.OpenRead("MyFile.txt");
await fileClient.UploadAsync(stream, overwrite: true);
Replace:
- <your-tenant-id> — from Azure AD
- <your-service-principal-client-id> — app registration's "Application (client) ID"
- <your-secret> — from app registration > Certificates & secrets
- <your-storage-account> — name of the account (you’ll see this in Fabric if you dig into the linked lakehouse)
Thanks,
Prashanth Are
MS Fabric community support