private static async Task ListSharesSample(ShareServiceClient shareServiceClient) { Console.WriteLine(); // Keep a list of the file shares so you can compare this list // against the list of shares that we retrieve . List <string> fileShareNames = new List <string>(); try { // Create 3 file shares. // Create the share name -- use a guid in the name so it's unique. // This will also be used as the container name for blob storage when copying the file to blob storage. string baseShareName = "demotest-" + System.Guid.NewGuid().ToString(); for (int i = 0; i < 3; i++) { // Set the name of the share, then add it to the generic list. string shareName = baseShareName + "-0" + i; fileShareNames.Add(shareName); // Create the share with this name. Console.WriteLine("Creating share with name {0}", shareName); ShareClient shareClient = shareServiceClient.GetShareClient(shareName); try { await shareClient.CreateIfNotExistsAsync(); Console.WriteLine(" Share created successfully."); } catch (RequestFailedException exRequest) { Common.WriteException(exRequest); Console.WriteLine( "Please make sure your storage account has storage file endpoint enabled and specified correctly in the app.config - then restart the sample."); Console.WriteLine("Press any key to exit"); Console.ReadLine(); throw; } catch (Exception ex) { Console.WriteLine(" Exception thrown creating share."); Common.WriteException(ex); throw; } } Console.WriteLine(string.Empty); Console.WriteLine("List of shares in the storage account:"); // List the file shares for this storage account var shareList = shareServiceClient.GetSharesAsync(); try { await foreach (ShareItem share in shareList) { Console.WriteLine("Cloud Share name = {0}", share.Name); } } catch (Exception ex) { Console.WriteLine(" Exception thrown listing shares."); Common.WriteException(ex); throw; } } catch (Exception ex) { Console.WriteLine(" Exception thrown. Message = {0}{1} Strack Trace = {2}", ex.Message, Environment.NewLine, ex.StackTrace); } finally { // If it created the file shares, remove them (cleanup). if (fileShareNames != null && shareServiceClient != null) { // Now clean up after yourself, using the list of shares that you created in case there were other shares in the account. foreach (string fileShareName in fileShareNames) { ShareClient share = shareServiceClient.GetShareClient(fileShareName); share.DeleteIfExists(); } } } Console.WriteLine(); }