/// <summary> /// Manage share properties /// </summary> /// <param name="shareServiceClient"></param> /// <returns></returns> private static async Task SharePropertiesSample(ShareServiceClient shareServiceClient) { Console.WriteLine(); // Create the share name -- use a guid in the name so it's unique. string shareName = "demotest-" + Guid.NewGuid(); ShareClient shareClient = shareServiceClient.GetShareClient(shareName); try { // Create Share Console.WriteLine("Create Share"); await shareClient.CreateIfNotExistsAsync(); // Set share properties Console.WriteLine("Set share properties"); await shareClient.SetQuotaAsync(100); // Fetch share properties ShareProperties shareProperties = await shareClient.GetPropertiesAsync(); Console.WriteLine("Get share properties:"); Console.WriteLine(" Quota: {0}", shareProperties.QuotaInGB); Console.WriteLine(" ETag: {0}", shareProperties.ETag); Console.WriteLine(" Last modified: {0}", shareProperties.LastModified); } catch (RequestFailedException exRequest) { Common.WriteException(exRequest); Console.WriteLine( "Please make sure your storage account is 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; } finally { // Delete share Console.WriteLine("Delete share"); await shareClient.DeleteIfExistsAsync(); } Console.WriteLine(); }
// <snippet_UploadFileWithSas> // <snippet_SetMaxShareSize> //------------------------------------------------- // Set the maximum size of a share //------------------------------------------------- public async Task SetMaxShareSizeAsync(string shareName, int increaseSizeInGiB) { const long ONE_GIBIBYTE = 10737420000; // Number of bytes in 1 gibibyte // Get the connection string from app settings string connectionString = ConfigurationManager.AppSettings["StorageConnectionString"]; // Instantiate a ShareClient which will be used to access the file share ShareClient share = new ShareClient(connectionString, shareName); // Create the share if it doesn't already exist await share.CreateIfNotExistsAsync(); // Ensure that the share exists if (await share.ExistsAsync()) { // Get and display current share quota ShareProperties properties = await share.GetPropertiesAsync(); Console.WriteLine($"Current share quota: {properties.QuotaInGB} GiB"); // Get and display current usage stats for the share ShareStatistics stats = await share.GetStatisticsAsync(); Console.WriteLine($"Current share usage: {stats.ShareUsageInBytes} bytes"); // Convert current usage from bytes into GiB int currentGiB = (int)(stats.ShareUsageInBytes / ONE_GIBIBYTE); // This line sets the quota to be the current // usage of the share plus the increase amount await share.SetQuotaAsync(currentGiB + increaseSizeInGiB); // Get the new quota and display it properties = await share.GetPropertiesAsync(); Console.WriteLine($"New share quota: {properties.QuotaInGB} GiB"); } }