Saturday, January 21, 2012

Share Status and Link on Socials in Windows Phone


Hope you all doing good.Sorry for the great delay here,I am almost working for all 7 days in week and that too on SQL Server – SSIS which is totally Alien to me but now I have good hands-on (In future you might get to see few post on that as well) for a critical project in my company. Due to this I couldn’t meet you here.

Today finally I got sometime to spend here and on Windows Phone and Silverlight, So I thought I can share something quickly with you before I get to other big topics.Our today’s topic is small but very unique and useful. Today I am going to talk about 2 set of Tasks and how to use them effectively available with new Windows Phone SDK as ShareStatusTask and ShareLinkTask  which comes under Microsoft.Phone.Tasks Namespace.So lets start with it.

So all we need is a simple Textbox and Button like this :


XAML Code :

<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <TextBox x:Name="txtStatus" Height="100" />
            <Button x:Name="btnShare" Height="100" Width="200" Margin="0,358,0,149" Click="btnShare_Click">Share</Button>

Namespace :

using Microsoft.Phone.Tasks;

C# Code :

private void btnShare_Click(object sender, RoutedEventArgs e)
    ShareStatusTask mySocialTasks = new ShareStatusTask();

    mySocialTasks.Status = txtStatus.Text.ToString() + System.DateTime.Now.ToString();


Above code is simple, We have a ShareStatusTask which comes with Property Status like this in ShareStatusTask which is Inherited from ShareTaskBase whose Show() method Causes the sharing dialog to be displayed to the user.

public string Status { get; set; }

public void Show();

So we are passing our/user defined Status message from Textbox txtStatus and appending DateTime with it (You can append anything or customize as per your need), Once you click on Share you will get Share Dialog like this :


Sorry for bit low screenshot, but you can see the list of Socials available on your device as

  • Windows Live
  • Facebook
  • Twitter
  • LinkedIn

If something new comes up tomorrow might get added to list, So all you need to do is pick the Socials and go ahead and share. Please note that this does not work on Windows Phone Emulator so you need to port this on actual Windows Phone Device.Also note that availability of Socials on your phone depends on your configuration and choice to have.So Don’t waste your time in emulator since it will not give any output or will not give any response.

On similar lines, we can implement ShareLinkTask Class like this :

private void btnShare_Click(object sender, RoutedEventArgs e)
          ShareLinkTask mySocialLinks = new ShareLinkTask();

          mySocialLinks.Title = "Explore .NET with Vikram Pendse";
          mySocialLinks.LinkUri = new Uri("", UriKind.Absolute);
          mySocialLinks.Message = txtStatus.Text.ToString() + System.DateTime.Now.ToString();


Choose “Windows Phone Device” and hit F5, you can see in Output window how it ports to Device and confirm the same like this it got displayed in my VS Output Window : (Observe lines in Bold)

------ Deploy started: Project: Demo_ShareStatus_Task, Configuration: Debug Any CPU ------
Deploying D:\Silverlight_On_Mobile\Demo_ShareStatus_Task\Demo_ShareStatus_Task\Bin\Debug\Demo_ShareStatus_Task.xap...
Connecting to Windows Phone Device...
The application is already installed on the device. Checking if an incremental deployment is possible...
Doing incremental deployment...
Updating information related to modified files...
Deployment of D:\Silverlight_On_Mobile\Demo_ShareStatus_Task\Demo_ShareStatus_Task\Bin\Debug\Demo_ShareStatus_Task.xap succeeded.
========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========

Now your app is ready to test on your WP Device, But make note of 2 things before you deploy :

  • Phone is ON and at Home Screen is visible and not pin locked
  • Zune instance is up and running

Now start from App list like this : (Demo_ShareStatus Icon)


Type your Message :


Share Link and Select Social Networks like this :


Finally you can see this happening in real on your respective Social Networks, Like in my case this got posted on my Facebook,Twitter and LinkedIn in one shot and at same time at all place like this :

Facebook :


Twitter :


LinkedIn :


So this is how you can share Status or Link in very short piece of Code by making use of ShareStatusTask and ShareLinkTask given by Windows Phone Development Environment. Now how to make use of these tasks in your app,I leave this for you to decide,Let me know if you need any help using this and also let me know your feedback.I hope you will enjoy this small post after a long time here. Now since I am bit relax from work schedule so I will be back soon with some more interesting posts on Windows Phone, WinRT and Silverlight soon.So keep visiting this place now.