private static string remoteFileTransferPath = @"/Data"; // Used for bulk transfer public static void Main(string[] args) { // Create Client Secret Credential var creds = new ClientSecretCredential(domain, clientId, clientSecret); // Create data lake file service client object DataLakeServiceClient serviceClient = new DataLakeServiceClient(new Uri(serviceUri), creds); var name = "sample-filesystem" + Guid.NewGuid().ToString("n").Substring(0, 8); // Create data lake file system client object DataLakeFileSystemClient filesystemclient = serviceClient.GetFileSystemClient(name); filesystemclient.CreateIfNotExists(); try { // Perform write with flush and read with seek PerformWriteFlushReadSeek(filesystemclient); // Upload and download RunFileTransfer(filesystemclient); // Change Acl and get acl properties SetAclAndGetFileProperties(filesystemclient); // Illustrate token refresh TestTokenRefresh(filesystemclient); } finally { filesystemclient.Delete(); } Console.WriteLine("Done. Press ENTER to continue ..."); Console.ReadLine(); }
private static string serviceUri = "FILL-IN-HERE"; // full account FQDN, not just the account name - it should look like https://{ACCOUNTNAME}.dfs.core.windows.net/ public static void Main(string[] args) { // Create Client Secret Credential var creds = new ClientSecretCredential(tenantId, applicationId, clientSecret); // Create data lake file service client object DataLakeServiceClient serviceClient = new DataLakeServiceClient(new Uri(serviceUri), creds); var name = "sample-filesystem" + Guid.NewGuid().ToString("n").Substring(0, 8); // Create data lake file system client object DataLakeFileSystemClient filesystemclient = serviceClient.GetFileSystemClient(name); filesystemclient.CreateIfNotExists(); try { long length; string fileName = "/Test/testFilename1.txt"; DataLakeFileClient file = filesystemclient.GetFileClient(fileName); // Upload a file - automatically creates any parent directories that don't exist length = BinaryData.FromString("This is test data to write.\r\nThis is the second line.\r\n").ToStream().Length; file.Upload(BinaryData.FromString("This is test data to write.\r\nThis is the second line.\r\n").ToStream(), true); file.Append(BinaryData.FromString("This is the added line.\r\n").ToStream(), length); file.Flush(length + BinaryData.FromString("This is the added line.\r\n").ToStream().Length); //Read file contents Response <FileDownloadInfo> fileContents = file.Read(); Console.WriteLine(BinaryData.FromStream(fileContents.Value.Content).ToString()); // Get the properties of the file PathProperties pathProperties = file.GetProperties(); PrintDirectoryEntry(pathProperties); // Rename a file string destFilePath = "/Test/testRenameDest3.txt"; file.Rename(destFilePath); file = filesystemclient.GetFileClient(destFilePath); Console.WriteLine("The file URI is " + file.Uri); // Enumerate directory foreach (var pathItem in filesystemclient.GetPaths("/Test")) { PrintDirectoryEntry(pathItem); } // Delete a directory and all it's subdirectories and files filesystemclient.DeleteDirectory("/Test"); } finally { filesystemclient.Delete(); } Console.WriteLine("Done. Press ENTER to continue ..."); Console.ReadLine(); }