locked
Connect programmaticaly Simple Windows Form to Azure Cloud Storage RRS feed

  • Question

  • Hi,

    How do I connect programmatically to azure cloud storage with a account name and account key form my windows form application

    Monday, November 8, 2010 10:38 AM

Answers

  • Hi Amrita,

    I just tried it and it worked fine for me. I used VS 2010 to build a WinForm application. Basically the form had two text boxes for storage account name and key and a button to validate those entries. Here is the code for button click event handler:

        private void button1_Click(object sender, EventArgs e)
        {
          try
          {
            string accountName = tbAccountName.Text;
            string accountKey = tbAccountKey.Text;
    
            StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(accountName, accountKey);
            CloudStorageAccount csa = new CloudStorageAccount(storageCredentialsAccountAndKey, true);
            var cloudTableClient = csa.CreateCloudTableClient();
            IEnumerable<string> tableNames = cloudTableClient.ListTables();
            int totaTables = tableNames.Count();
            MessageBox.Show("All is well");
          }
          catch (Exception excep)
          {
            MessageBox.Show("Something is wrong");
          }
        }
    

    A few things you would need to keep in mind:

    1. Make sure you add a reference to Microsoft.WindowsAzure.StorageClient.dll.

    2. If you're building a .net 4.0 app, make sure that the target framework is .Net Framework 4 and not the client profile.

    Hope this helps.

    Thanks

    Gaurav

     

     

    Monday, November 8, 2010 2:44 PM

All replies

  • Hi,

    I suggest to install the Azure Training kit which provides you with a few examples on how to connect and use Azure Storage.

    Hope this helps.

    Edward

     

    Monday, November 8, 2010 10:53 AM
  • I could not find anythng much in the training kit.

    I have a windows form application where the user inputs a account name and account key. I need to check through my program if the account exists on cloud or else not allow the user to proceed with the other functionalities. Could you please help.

    Monday, November 8, 2010 12:16 PM
  • Hi Amrita,

    I just responded to a similar question: http://social.msdn.microsoft.com/Forums/en-US/windowsazuredata/thread/50880f90-a0a7-439b-98ad-bd9fec97efbd .

    Do take a look at that.

    Hope this helps.

    Thanks

    Gaurav Mantri

    Cerebrata Software

    http://www.cerebrata.com

    Monday, November 8, 2010 1:27 PM
  • I have the same scenario. But in order to write

    var account = new CloudStorageAccount(new StorageCredentialsAccountAndKey(accountName, sharedKey), false);

    I need to add

    using Microsoft.WindowsAzure.StorageClient;

    But this is not possible in Windows Forms application.

    Could you please suggest something for this?

    Monday, November 8, 2010 1:53 PM
  • Hi Amrita,

    I just tried it and it worked fine for me. I used VS 2010 to build a WinForm application. Basically the form had two text boxes for storage account name and key and a button to validate those entries. Here is the code for button click event handler:

        private void button1_Click(object sender, EventArgs e)
        {
          try
          {
            string accountName = tbAccountName.Text;
            string accountKey = tbAccountKey.Text;
    
            StorageCredentialsAccountAndKey storageCredentialsAccountAndKey = new StorageCredentialsAccountAndKey(accountName, accountKey);
            CloudStorageAccount csa = new CloudStorageAccount(storageCredentialsAccountAndKey, true);
            var cloudTableClient = csa.CreateCloudTableClient();
            IEnumerable<string> tableNames = cloudTableClient.ListTables();
            int totaTables = tableNames.Count();
            MessageBox.Show("All is well");
          }
          catch (Exception excep)
          {
            MessageBox.Show("Something is wrong");
          }
        }
    

    A few things you would need to keep in mind:

    1. Make sure you add a reference to Microsoft.WindowsAzure.StorageClient.dll.

    2. If you're building a .net 4.0 app, make sure that the target framework is .Net Framework 4 and not the client profile.

    Hope this helps.

    Thanks

    Gaurav

     

     

    Monday, November 8, 2010 2:44 PM
  • Hi Gaurav thanks a lot. It is working for me. I had to change target framework which I had been missing and hence could not use the dll.
    Tuesday, November 9, 2010 3:22 AM