Code to Share Status or Links on Social Media sites in Windows Phone

While creating application for Windows Phone you may come across requirement to share certain message from your application on social media sites configured on user device. You can do it using ShareStaus Task. ShareStausTask class is defined as below. It is inherited from ShareTaskBase class.

image

 

ShareStatus Task Launcher allows an application to launch a dialog that allows user to share status message on social network site.

A status message can be shared as below,


ShareStatusTask shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = "Hey I am Shared By DebugMode";
shareStatusTask.Show();


You may come across other scenario where you may need to share HyperLink across Social Media sites from your application. You can do that using launcher ShareLinkTask.

ShareLinkTask class is defined as below,

image

ShareLink Task Launcher allows an application to launch a dialog that allows user to share links on social network site.

A link can be shared as below,



ShareLinkTask shareLinkTask = new ShareLinkTask();
shareLinkTask.Title = "DebugMode";
shareLinkTask.LinkUri = new Uri("http://debugmode.net", UriKind.Absolute);
shareLinkTask.Message = "Post of DebugMode.";
shareLinkTask.Show();

These launchers will be launched only if user has configured social media sites on their device. I hope this post is useful. Thanks for reading.

How to Use the ConnectionSettings Task for Windows Phone

ConnectionSettings Task allows user to set and adjust device network settings. ConnectionSettings task is defined in Microsoft.Phone.Tasks namespace as below,

image

User can set device network setting to any of the following

image

If you want to set Network connection setting to WiFi, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.WiFi;
connectionSettingsTask.Show();

image

If you want to set Network connection setting to Bluetooth, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Bluetooth;
connectionSettingsTask.Show();

image

If you want to set Network connection setting to Cellular, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.Cellular;
connectionSettingsTask.Show();

image

If you want to set Network connection setting to Airplane mode, you can set it as below,


ConnectionSettingsTask connectionSettingsTask = new ConnectionSettingsTask();
connectionSettingsTask.ConnectionSettingsType = ConnectionSettingsType.AirplaneMode;
connectionSettingsTask.Show();


image

In this way you can set the network setting of device using ConnectionSettings task. I hope this post is useful. Thanks for reading

Learn and Win Windows Phone: A great event by Pune User Group and I Unlock Joy Program

imageimage

Pune user group along with Microsoft I unlock joy program brings a Learn and Win Windows Phone event in Pune.

Read about Pune User Group here and I Unlock Joy Program here

This is a great opportunity for developers to learn development of Windows Phone from veterans like Mayur Tendulkar and Amol Vaidya. This program will run on four consecutive Saturday starting from 28th January 2012.

You can register for program here

You can find important information at below given links,

 

About Program

http://iunlockjoy.cloudapp.net/

Speakers

http://iunlockjoy.cloudapp.net/Speakers

Agenda

http://iunlockjoy.cloudapp.net/Agenda

Venue

http://iunlockjoy.cloudapp.net/Venue

FAQ

http://iunlockjoy.cloudapp.net/FAQ

I hope to see you there and wish very good luck for Windows Phone.

 

Creating Alarm and Reminder in Windows Phone

In this post we will see the way to create Alarm and Reminder in Windows Phone.

Creating Alarm

  • Alarm can be created using the Alarm class.
  • Alarm class is part of Microsoft.Phone.Scheduler namespace.
  • Alarm class takes name of the alarm as the input parameter of the constructor.
  • Name of the alarm must be unique within the application.
  • Other properties of Alarm class are as below,

image

You can find explanations of properties are as below. Alarm class is inherited from ScheduleNotification class. Some of the properties are of base class.

image

Alarm can be created as below,


var newAlaram = new Alarm("myalarm")
{
Content="Hey Office Time",
BeginTime= DateTime.Now.AddMinutes(2),
RecurrenceType = RecurrenceInterval.Daily,
ExpirationTime = DateTime.Today.AddDays(30),
// sound= new Uri("music1.wav",UriKind.Relative)
};


ScheduledActionService.Add(newAlaram);


In above code, last line is adding alarm to the phone. ScheduledActionService class add method is used to add alarm to the phone. On running you should be getting alarm after 2 minute of current time as below,

image

Best practice to give name of alarm as a GUID. Since name of the alarm must be unique in the application and it is not visible to the user so it should be given the name as GUID.

Creating Reminder

  • Reminder can be created using Reminder class.
  • Reminder class is part of Microsoft.Phone.Scheduler namespace
  • It is inherited from ScehduleNotification class.
  • Name of the Reminder must be unique in the application
  • Title of the reminder can be set.
  • Custom sound is not supported in reminder. All reminder plays same sound.
  • Reminder can be navigated to a specific page on tapping by the user. This was not supported in Alarm.
  • Other properties are as below,

 

image

Various properties of Reminder is explained below,

image

Reminder can be created as below,


Reminder reminder = new Reminder("myreminder")
{
Title = "Debugmode app reminder",
Content = "Hey Go to party",
BeginTime = DateTime.Now.AddMinutes(2),
RecurrenceType = RecurrenceInterval.Daily,
ExpirationTime = DateTime.Today.AddDays(30),
NavigationUri = new Uri("Page1.xaml", UriKind.Relative)

};

ScheduledActionService.Add(reminder);



In above code, last line is adding reminder to the phone. ScheduledActionService class add method is used to add reminder to the phone. On running you should be getting reminder after 2 minute of current time as below,

image

On tapping user will be navigated to Page1.xaml.

This is how you can create and schedule Alarm and Reminder in Windows Phone. I hope this post is useful. Thanks for reading.

 

A Tribute to world’s Youngest MCP Arfa Karim

We have witnessed last year God recalled best of the people from our world to his world. This year God continuing doing same recalling youngest Microsoft Certified Professional Arfa Karim.

You may have gone from this world; not from our heart; you will be remembered always as an inspiration “

image

She was the youngest Microsoft Certified Professional in the world. Read about her on Wikipedia

On 14th January 2012, she has started journey to newer and better world leaving all of us behind. This world will remember us always.

image

Source of Images : various sites on web

May her soul rest in peace

How to work with Custom Method in WCF Data Service?

In this post we will see how could we expose a custom method in WCF Data Service? There are three steps involved in doing that

  1. Create a partial class of Entity class and add desired custom method in that.
  2. Add a method with WebGet attribute in service class. This method will make a call to the custom method added in partial entity class.
  3. At the client side call custom method using Execute method

Add Method in Partial Entity class

Create a partial class for entity class. If you are working on School database and your entity class name is SchoolEntities then add one more partial class along with custom method.



namespace WebApplication10
{
public partial class SchoolEntities
{
public string MyCustomMethod()
{
return "Hey I am returned from Custom Method ";
}

}
}

Modifying Service Class

Once you have added custom method in partial entity class, next you need to add method in service class (.svc) with WebGet attribute

image

Above function is creating instance of entity class and making a call to custom method. Custom method will be called at URL baseaddress/service.svc/CustomMethod

Putting all together service class with one custom method will be as below,


using System.Data.Services;
using System.Data.Services.Common;
using System.ServiceModel.Web;

namespace WebApplication10
{
public class WcfDataService1 : DataService<SchoolEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{

config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}


[WebGet]
public string CustomMethod()
{
SchoolEntities entities = new SchoolEntities();
return entities.MyCustomMethod();
}



}
}


Calling custom method at client side

To call custom method at client side you need to make call to Execute method on instance of Entity class. Execute is a generic method and it takes return type of custom method as parameter. In this case return type of custom method is string. Execute method returns IEnuramble. As the parameter to Execute method you need to pass URI od custom method.

image

We can print returned value from custom method from WCF Data Service as below,


using System;
using ConsoleApplication32.ServiceReference1;

namespace ConsoleApplication32
{
class Program
{
static void Main(string[] args)
{
SchoolEntities entities = new SchoolEntities
(new Uri("http://localhost:2580/WcfDataService1.svc/"));
var result = entities.Execute<string>
(new Uri("http://localhost:2580/WcfDataService1.svc/CustomMethod"));

foreach (var r in result)
{
Console.WriteLine(r.ToString());
}
Console.ReadKey(true);


}
}
}


On running of above code you should be getting output as below,

clip_image002

In this way you can work with custom method in WCF Data service. I hope this post is useful. Thanks for reading.

Flyout control in Windows 8 HTML JavaScript Metro Application

In this post, I will discuss how to work with Flyout in Windows 8 Metro application. Flyout is a type of UI surface in Windows 8 metro application. It is used to show simple message or popup. If user touches or clicks anywhere on the screen then Flyout disappears. It usually used to collect simple user information or show some message. Flyout should be as simple as possible. It should not have complex UI. A usual flyout can be like below,

image

Flyout can be created deceptively as below.

clip_image002

Inside Flyout we can put any HTML elements. As purpose of this post I am going to put sports as option and user can select out of that options. After putting sports options Flyout div will get modified as below,

clip_image004

User can select sports from above Flyout. As the design of the page, we have put a button and output div. We are going to popup a fly out on click event of a button. On selection of a sports option in Flyout, we will display that in output div and Flyout will disappear.

Default.html


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>WinWebApp1todelete</title>
<!-- WinJS references -->
<link rel="stylesheet" href="/winjs/css/ui-dark.css" />
<script src="/winjs/js/base.js"></script>
<script src="/winjs/js/ui.js"></script>
<script src="/winjs/js/binding.js"></script>
<script src="/winjs/js/controls.js"></script>
<script src="/winjs/js/animations.js"></script>
<script src="/winjs/js/uicollections.js"></script>
<script src="/winjs/js/wwaapp.js"></script>
<link rel="stylesheet" href="/css/default.css" />
<script src="/js/default.js"></script>
</head>
<body>
<button id="butonchooseSports" type="button"
style="margin-left:900px;
margin-top:20px;font-size:x-large">
Choose Sports
</button>
<div id="sportsFlyout" data-win-control="WinJS.UI.Flyout" aria-label="{Format text flyout}">
<label for="scenario3TextColor">choose sports</label>
<br />
<select id="scenario3TextColor">
<option value="cricket">Cricket</option>
<option value="football">FootBall</option>
<option value="hocky">Hocky</option>
<option value="tenis">Tenis</option>
<option value="rugby">Rugby</option>
<option value="golf">Golf</option>
</select>
</div>
<div style="margin-left:900px;
margin-top:300px;font-size:x-large" id="outputDiv"></div>
</body>
</html>

In code behind on click event of the button Flyout can be shown as below function.

clip_image002[8]

Here we are,

  • Selecting Flyout div as win control.
  • Calling Show function to display Flyout.
  • There are input parameters of Show function. First parameter is id of button. On click event of this input button Flyout will get displayed.
  • Second parameter is position of the Flyout. Other possible value of this parameter could be top.

We are putting all code together as below,

Default.js


(function () {
'use strict';
// Uncomment the following line to enable first chance exceptions.
// Debug.enableFirstChanceException(true);
var choosesportsbutton;
WinJS.Application.onmainwindowactivated = function (e) {
if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
// TODO: startup code here

WinJS.UI.processAll().then(function () {
choosesportsbutton = document.getElementById("butonchooseSports");
choosesportsbutton.addEventListener('click', showflyout);



});
}

function showflyout()
{
var flyOut = document.getElementById("sportsFlyout").winControl;
flyOut.addEventListener('change', ChangedSportsValue);
flyOut.show(choosesportsbutton, "bottom");
}

function ChangedSportsValue(e) {

var res = document.getElementById('scenario3TextColor').value;
document.getElementById('outputDiv').innerText = "You have selected " + res;
}
}

WinJS.Application.start();
})();


In above code we are,

  • Displaying Flyout
  • Attaching change event on sports option list. In this post Id of Sports option in Flyout div is seenario3TextColor
  • Attaching click event to button and on click showing Flyout.
  • Displaying selected sports in output div

If you run, on the click event of button you should get Flyout to choose the sports as below,

image

I hope this post is useful. Thanks for reading

 

Data from Cloud on Windows Phone

Data from cloud on the phone “, it may appear as a buzzing sentence to you. In this post, I try to minimize complexity of accessing data from cloud to be specific from SQL Azure in Windows Phone. In this post I will walkthrough step by step accessing data from SQL Azure in Windows Phone.

image

I have divided task in three parts.

image

We will expose all the operation on Student database residing in SQL Azure as WCF REST Service. In this case REST is working on JSON data.

Setting up project

Very first let us set up the project. We want to expose operation as WCF Service hosted in Windows Azure. So to do that, you need to create WCF Service Role.

image

Creating Data Model

We are going to create DataModel using LINQ to SQL Class. To create DataModel right click on project then select add new item and choose LINQ to SQL Class form Data tab.

clip_image002

Next you need to choose the option Server explorer and add a new connection. In Add new connection windows provide database information for SQL Azure.

clip_image003

From drop down you choose database of your choice. In this case I am going to select Student database. After selecting database on the designer, I am dragging and dropping table Person. On the designer (dbml) you should have Person class .As of now we have created DataModel. In solution explorer you will find dbml and dbml.cs file has been created.

Creating Service

Data Transfer Object class represents entity from Data Model we want to expose as part of service contract. We need to create Data Transfer Object class. This class will act as Data Contract between Service and Client. To add a Data Transfer Object class go ahead and add a new class to project as below.

PersonDTO.cs


using System.Runtime.Serialization;

namespace RESTJSONStudentsData
{
[DataContract]
public class PersonDTO
{
[DataMember]
public string StudentId { get; set; }
[DataMember]
public string FirstName { get; set; }
[DataMember]
public string LastName { get; set; }

}
}


We have created Data Contract. Now we need to create Service Contract. Service Contract must be attributed to behave as WCF REST Service. I have set request and response format as JSON.

IService1.cs


using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace RESTJSONStudentsData
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate="/Persons",
RequestFormat=WebMessageFormat.Json,
ResponseFormat=WebMessageFormat.Json]
List<PersonDTO> GetPersons();
}
}

Now we need to implement the service. In Service implementation, I am querying Person table of Student database using LINQ and constructing List of PersonDTO.

Service1.svc.cs


using System.Collections.Generic;
using System.Linq;

namespace RESTJSONStudentsData
{

public class Service1 : IService1
{

public List<PersonDTO> GetPersons()
{
DataClasses1DataContext context = new DataClasses1DataContext();
List<PersonDTO> result = (from r in context.Persons
select new PersonDTO
{
FirstName = r.FirstName,
LastName = r.LastName,
StudentId = r.PersonID.ToString()
}).ToList<PersonDTO>();
return result;

}
}
}

Next in this section we need to configure service. We need to configure service webHttpBinding to eanble it as REST Service. So in Web.Config we need to do the below changes.

Web.Config


<system.serviceModel>

<behaviors>
<serviceBehaviors>
<behavior name ="servicebehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="restbehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name ="RESTJSONStudentsData.Service1" behaviorConfiguration="servicebehavior" >
<endpoint name ="RESTEndPoint"
contract ="RESTJSONStudentsData.IService1"
binding ="webHttpBinding"
address ="rest"
behaviorConfiguration ="restbehavior"/>

</service>
</services>

<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>


After configuring, Service ready for hosting. We need to host it in Windows Azure Portal. For that right click on Windows Azure project and select Package and Upload this package to one of the hosted service. Up to this step we have created and hosted WCF REST Service returning JSON.

Consuming Service in Windows Phone

To consume REST Service in Windows Phone 7 and then parse JSON, you need to add below references in Windows Phone 7 project.

clip_image001

We need a class to represent PersonDTO class .For that makes a class called Person at client side.

Person.cs


namespace PhoneApp11
{
public class Person
{
public string StudentId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }

}
}

As the design of the page I have put a ListBox. Data returned from cloud table will get bind to this ListBox.

MainPage.xaml



<phone:PhoneApplicationPage
x:Class="PhoneApp11.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True"
Loaded="PhoneApplicationPage_Loaded">

<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="data from SQL Azure" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="students" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox x:Name="lstPerson" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding LastName}" Style="{StaticResource PhoneTextTitle1Style}" />
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding StudentId}" Style="{StaticResource PhoneTextGroupHeaderStyle}" />
<TextBlock Text="{Binding FirstName}" Style="{StaticResource PhoneTextTitle2Style}" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</Grid>
</Grid>

</phone:PhoneApplicationPage>


We need to make a call to the service and on download of JSON data as string; we need to parse JSON using System.RunTime.Serlization.JSON

MainPage.xaml.cs


using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using Microsoft.Phone.Controls;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;

namespace PhoneApp11
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}

private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{


WebClient proxy = new WebClient();
proxy.DownloadStringCompleted +=
new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
proxy.DownloadStringAsync(new Uri("http://debugmodesqlazurejson.cloudapp.net/Service1.svc/rest/Persons"));


}

void proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
Stream stream = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));
DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(List<Person>));
List<Person> result = (List < Person >) obj.ReadObject(stream);
lstPerson.ItemsSource = result;
}

}
}


In above code we are creating DataContractJsonSerializer object and passing List of Person to deseriliaze because service is returning list of PersonDTO. And as mentioned earlier Person class is representing PersonDTO class. Now go ahead and press F5 to run the application. You should be getting details of Person table from School database residing on SQL Azure.

clip_image002[7]

In later post we will explore further to perform other CRUD operations. I hope this post is useful. Thanks for reading.

Windows Azure Storage Client Library for Windows Phone: Part 1

Windows Azure Storage Client Library allows you to perform operations on Windows Azure storage from Windows Phone. Using Windows Azure Storage Client, you can

  1. Perform operations on Table
  2. Perform operations on Queue
  3. Perform Operations on BLOB

If you are not using Windows Azure Storage Client Library then to work with Windows Azure Storage you may need to create a WCF Service. Windows Phone will make a call to Service and Service will use Windows Azure Storage library to perform operations on Azure Storage. However using Windows Azure Storage Client for Windows Phone, you can directly perform operations on Windows Azure Storage.

You can get Windows Azure Storage Client Library and install it using NuGet. Read more about NuGet here. Once you have installed NuGet go ahead and create a Windows Phone 7.1 application by choosing target Windows Phone Version 7.1

image

After successful creation of project go to Tools then Library Package Manager, you will get option for Package Manager Console. Go ahead and select that option.

image

In bottom of Visual studio you will get Package Manage Console. Go ahead and install Phone.Storage package to the project.

You can install a package with below command

PM> Install-Package Phone.Storage

image

After successful installation of Phone.Storage package, you should have below references and file in solution explorer.

image

StorageInitializer.cs is very important class. In this class you can set whether you want to perform operation on local development fabric storage or on the azure storage. If you closely look into this file, you will find there are three sections.

  1. To configure to connect with local development fabric storage or Windows Azure Storage Emulator.
  2. To configure to connect with Windows Azure Web Role that contains Windows Azure Storage Proxies
  3. To configure to connect with Windows Azure Storage directly.

All the settings are commented but to work with storage of Windows Azure Emulator. If you want to work with Windows Azure Storage directly, you can do that by commenting third section of the file and providing Account Name and Account Key. Below is the uncommented section in file StorageInitalizer.cs. You need to provide your Windows Azure Storage account name and key.

image

Next let us say you want to create a table called Student. For that add a class called Student. Student entity class is inherting TableServiceEntity class.



using Microsoft.WindowsAzure.Samples.Phone.Storage;


namespace PhoneApp9
{
public class Student :TableServiceEntity
{
public string Name { get; set; }
public string RollNumber { get; set; }
public string Grade { get; set; }
}
}


Next as the design of the page, I have put a button and on click event of the button, Student table will get created if not exist and one row will get added.

Design of the page is as below,



<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>

<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button x:Name="btnCreateTable" Height="100" Content="Create Table" Margin="46,254,128,254" Click="btnCreateTable_Click" />
</Grid>
</Grid>


On the click event of the button, first you need to resolve table client as below. Set the table name.

clip_image002

After resolving Table client, you need to create table as below,

clip_image003

Once table is created you need to resolve the context to add rows in the table.

clip_image005

You can very much modify above code by getting value to be inserted from the user. In this case I am hardcoding the vale. On putting all codes together you should have below code behind.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.WindowsAzure.Samples.Phone.Storage;

namespace PhoneApp9
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}

private void btnCreateTable_Click(object sender, RoutedEventArgs e)
{
var tableClient = CloudStorageContext.
Current.Resolver.
CreateCloudTableClient();

var tableName = "Student";

tableClient.CreateTableIfNotExist(
tableName,
p =>
{
var context = CloudStorageContext.
Current.
Resolver.
CreateTableServiceContext();
var sampleData = new Student
{  Grade = "A",
Name="DJ",
RollNumber="1",
PartitionKey="s2",
RowKey="s"
};

context.AddObject(tableName, sampleData);

context.BeginSaveChanges(
asyncResult =>
{
var response = context.EndSaveChanges(asyncResult);

},
null);
});

}
}
}


Once you run on click event of the button you should able to add row in the table. I hope this post is useful. Thanks for reading.

How to work with NuGet?

NuGet is a visual studio extension and you can get it from here. It helps you

  1. Add library and tools to visual studio .Net Framework project
  2. Remove library and tools to visual studio .Net Framework project
  3. Update library and tools to visual studio .Net Framework project

NuGet does all the necessary tasks required to work with a library or tool. It

  • Modifies config files
  • Add or remove references
  • Sync updated feature with source control of the project

Downloading and Installing

To download go to http://nuget.codeplex.com/ and click on Install NuGet

clip_image001

You will be redirected to http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c . You need to click download to download NuGet Package Manager.

clip_image003

After downloading click package to install .

clip_image004

It will take fraction of seconds to install it.

clip_image005

After successful installation if you go to Tools then Library Package Manager, you will get option for Package Manager.

clip_image006

If you want to check all the available NuGet commands, you can check as below,

clip_image007

If you want to see list of package available you can see as below. In below command

clip_image008

You can install a package with below command

clip_image010

In this way you can update and remove a package as well.

You can read full documentation here . Now what are you waiting for? Go ahead and use NuGet. I hope this post will add some value in your learning. Thanks for reading.