public void Update()
{
//specify storage credentials.
StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey("storageaccountname","key");
//create a reference to your storage account, passing in your credentials.
CloudStorageAccountstorageAccount = new CloudStorageAccount(credentials , true);
//create object to CloudTableClient to access the Table service.
CloudTableClient tableClient = new CloudTableClient (storageAccount.TableEndpoint.ToString(),
storageAccount.Credentials);
//creates the table if not exist
tableClient.CreateTableIfNotExist("TableName");
//get data context
TableServiceContext context = tableClient.GetDataServiceContext();
//table object which inherits from TableServiceEntity
TableEntity obj = new TableEntity();
//partitionkey of the existing table entity
obj.PartitionKey= partitionKey;
//rowkey of the existing table entity
obj.RowKey = rowkey;
context.AttachTo("TableName", obj, "*");
context.UpdateObject(obj);
context.SaveChanges(SaveChangesOptions.ReplaceOnUpdate);
}
//table entity class
public class TableEntity :TableServiceEntity
{
//constructor
public TableEntity()
{
}
//user id propery
public string UserId{get;set;}
}
Let me know, if you have any feedback. Mail me for source code. Enjoy reading my articles…
sekhartechblog@gmail.com
No comments:
Post a Comment