Skip to content

Instantly share code, notes, and snippets.

@bohdanszymanik
Created July 11, 2013 10:45
Show Gist options
  • Save bohdanszymanik/5974459 to your computer and use it in GitHub Desktop.
Save bohdanszymanik/5974459 to your computer and use it in GitHub Desktop.
WindowsAzureTableStorage basic F# script sample
#r @"C:\wd\AzureTxnUploader\packages\WindowsAzure.Storage.2.0.6.0\lib\net40\Microsoft.WindowsAzure.Storage.dll"
#r @"C:\wd\AzureTxnUploader\packages\Microsoft.Data.OData.5.2.0\lib\net40\Microsoft.Data.OData.dll"
#r @"C:\wd\AzureTxnUploader\packages\Microsoft.Data.Edm.5.2.0\lib\net40\Microsoft.Data.Edm.dll"
#r @"C:\wd\AzureTxnUploader\packages\System.Spatial.5.2.0\lib\net40\System.Spatial.dll"
#r "Microsoft.WindowsAzure.ServiceRuntime"
#r "System.Data.Services.Client"
#r "System.Linq"
open System
open Microsoft.WindowsAzure
open Microsoft.WindowsAzure.Storage
open System.Windows.Forms
// Account name and key. Modify for your account.
let accountName = "someAccountName"
let accountKey = "someAccountKey"
//Get a reference to the storage account, with authentication credentials
let credentials = new Auth.StorageCredentials(accountName, accountKey)
let storageAccount = new CloudStorageAccount(credentials, true)
storageAccount.BlobEndpoint = Uri("http://someAccountName.blob.core.windows.net/")
storageAccount.TableEndpoint = Uri("http://someAccountName.table.core.windows.net/")
storageAccount.QueueEndpoint = Uri("http://someAccountName.queue.core.windows.net/")
//Create a new client object.
let blobClient = storageAccount.CreateCloudBlobClient()
let tableClient = storageAccount.CreateCloudTableClient()
// Retrieve a reference to a container.
let container = blobClient.GetContainerReference("mycontainer")
// Create the container if it does not already exist.
container.CreateIfNotExists()
let table = tableClient.GetTableReference("someTable")
table.CreateIfNotExists()
// put some entities into the table
type YearMonthTxns() =
inherit Table.TableEntity()
member val txns = "" with get, set
let someYearMonthTxns = YearMonthTxns( PartitionKey = "2013", RowKey = "06", txns = "test" )
let cmd = Table.TableOperation.Insert(someYearMonthTxns)
let tableResult = table.Execute(cmd)
// Output container URI to debug window.
System.Diagnostics.Debug.WriteLine(container.Uri)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment