public void CreateDeleteTable() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies1p1"; #region Snippet:TablesSample1CreateClient // Construct a new <see cref="TableServiceClient" /> using a <see cref="TableSharedKeyCredential" />. var serviceClient = new TableServiceClient( new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); #endregion #region Snippet:TablesSample1CreateTable // Create a new table. The <see cref="TableItem" /> class stores properties of the created table. #if SNIPPET string tableName = "OfficeSupplies1p1"; #endif TableItem table = serviceClient.CreateTable(tableName); Console.WriteLine($"The created table's name is {table.Name}."); #endregion #region Snippet:TablesSample1DeleteTable // Deletes the table made previously. #if SNIPPET string tableName = "OfficeSupplies1p1"; #endif serviceClient.DeleteTable(tableName); #endregion #region Snippet:TablesSample1GetTableClient #if SNIPPET string tableName = "OfficeSupplies1p2"; #else tableName = "OfficeSupplies1p2"; #endif var tableClient = serviceClient.GetTableClient(tableName); #endregion #region Snippet:TablesSample1CreateTableClient #if SNIPPET var tableClient = new TableClient( #else tableClient = new TableClient( #endif new Uri(storageUri), tableName, new TableSharedKeyCredential(accountName, storageAccountKey)); #endregion #region Snippet:TablesSample1TableClientCreateTable tableClient.Create(); #endregion #region Snippet:TablesSample1TableClientDeleteTable tableClient.Delete(); #endregion }
/// <summary> /// Deletes the table on the service. /// </summary> /// <param name="tableName"></param> /// <param name="cancellationToken"></param> /// <returns>True if table was deleted; otherwise, false.</returns> public bool DeleteTable(string tableName, CancellationToken cancellationToken) { this.EnsureTableServiceClient(); TableClient tableClient = this.tableServiceClient.GetTableClient(tableName); Response response = tableClient.Delete(cancellationToken); return(response != null); }
public void CreateDeleteEntity() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies2p1"; string partitionKey = "somePartition"; string rowKey = "A1"; string rowKeyStrong = "B1"; #region Snippet:TablesSample2CreateTableWithTableClient // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />. var client = new TableClient( tableName, new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); // Create the table in the service. client.Create(); #endregion #region Snippet:TablesSample2CreateEntity // Make an entity by defining a <see cref="Dictionary"> that includes the partition and row key. var entity = new TableEntity(partitionKey, rowKey) { { "Product", "Markers" }, { "Price", 5.00 }, }; // Insert the newly created entity. client.CreateEntity(entity); #endregion #region Snippet:TablesSample2CreateStronglyTypedEntity // Make a strongly typed entity by defining a custom class that extends <see cref="TableEntity">. var strongEntity = new OfficeSupplyEntity { PartitionKey = partitionKey, RowKey = rowKeyStrong, Product = "Notebook", Price = 3.00 }; // Insert the newly created entity. client.CreateEntity(strongEntity); #endregion #region Snippet:TablesSample2DeleteEntity // Delete the entity given the partition and row key. client.DeleteEntity(partitionKey, rowKey); #endregion #region Snippet:TablesSample2DeleteTableWithTableClient client.Delete(); #endregion }
public void CreateDeleteEntity() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies2p1"; string partitionKey = "Stationery"; string rowKey = "A1"; string rowKeyStrong = "B1"; #region Snippet:TablesSample2CreateTableWithTableClient // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />. var tableClient = new TableClient( tableName, new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); // Create the table in the service. tableClient.Create(); #endregion #region Snippet:TablesSample2CreateDictionaryEntity // Make a dictionary entity by defining a <see cref="TableEntity">. var entity = new TableEntity(partitionKey, rowKey) { { "Product", "Marker Set" }, { "Price", 5.00 }, { "Quantity", 21 } }; Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}."); #endregion #region Snippet:TablesSample2AddEntity // Add the newly created entity. tableClient.AddEntity(entity); #endregion #region Snippet:TablesSample2CreateStronglyTypedEntity // Create an instance of the strongly-typed entity and set their properties. var strongEntity = new OfficeSupplyEntity { PartitionKey = partitionKey, RowKey = rowKeyStrong, Product = "Notebook", Price = 3.00, Quantity = 50 }; Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}."); #endregion // Add the newly created entity. tableClient.AddEntity(strongEntity); #region Snippet:TablesSample2DeleteEntity // Delete the entity given the partition and row key. tableClient.DeleteEntity(partitionKey, rowKey); #endregion #region Snippet:TablesSample2DeleteTableWithTableClient tableClient.Delete(); #endregion }
public void CreateDeleteTable() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies1p1"; #region Snippet:TablesSample1CreateClient // Construct a new "TableServiceClient using a TableSharedKeyCredential. var serviceClient = new TableServiceClient( new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); #endregion #region Snippet:TablesSample1CreateTable // Create a new table. The TableItem class stores properties of the created table. #if SNIPPET string tableName = "OfficeSupplies1p1"; #endif TableItem table = serviceClient.CreateTableIfNotExists(tableName); Console.WriteLine($"The created table's name is {table.Name}."); #endregion #region Snippet:TablesMigrationCreateTableWithClient // Get a reference to the TableClient from the service client instance. var tableClient = serviceClient.GetTableClient(tableName); // Create the table if it doesn't exist. tableClient.CreateIfNotExists(); #endregion #region Snippet:TablesSample1DeleteTable // Deletes the table made previously. #if SNIPPET string tableName = "OfficeSupplies1p1"; #endif serviceClient.DeleteTable(tableName); #endregion #region Snippet:TablesSample1GetTableClient #if SNIPPET string tableName = "OfficeSupplies1p2"; var tableClient = serviceClient.GetTableClient(tableName); #else tableName = "OfficeSupplies1p2"; tableClient = serviceClient.GetTableClient(tableName); #endif #endregion #region Snippet:TablesSample1CreateTableClient #if SNIPPET var tableClient = new TableClient( #else tableClient = new TableClient( #endif new Uri(storageUri), tableName, new TableSharedKeyCredential(accountName, storageAccountKey)); #endregion #region Snippet:TablesSample1TableClientCreateTable tableClient.CreateIfNotExists(); #endregion #region Snippet:TablesSample1TableClientDeleteTable tableClient.Delete(); #endregion }
/// <summary> /// Delete the table /// </summary> public void DeleteTable() { CloudTable.Delete(); }