Retrieving a WebPage Title and Sharing it with the ShareLinkTask in WP7

image

 

Introduction

The ShareLinkTask introduced in Windows Phone SDK 7.1 enables users to share a link on various social networks like Twitter, Facebook and LinkedIn. The only thing that I wish that it had was a way to grab the page title for the link before posting. I found myself typing the page title and thought I’d write some simple code and share with everyone. Below is a snapshot of a post to Facebook that automatically added the page title to the post.

image

ShareLinkTask Intro

The following code is all you need to share links on Social Media Networks with WP SDK 7.1.

ShareLinkTask shareLinkTask = new ShareLinkTask();

shareLinkTask.Title = "Telerik";
shareLinkTask.LinkUri = new Uri("http://www.telerik.com", UriKind.Absolute);
shareLinkTask.Message = "Here are some great controls for Windows Phone 7.";

shareLinkTask.Show();

It will pop up a list of all the Social Media accounts that the user has registered on their device and after you select it then it will post automatically.

Instead of hard coding the title or message, we can add in the following code in and get the page title automatically.

WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri("http://www.telerik.com", UriKind.RelativeOrAbsolute));
wc.DownloadStringCompleted += (s, ev) =>
{
    strTitle = Regex.Match(ev.Result, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase).Groups["Title"].Value;
};

Wrap-up

Thanks for the help Regex! This was fairly painless process that only took a few minutes! If this post helped you or you know a better way then I’d love to hear from you in the comments below.



windows-phone7 wp7
Posted by: Michael Crump
Last revised: 07 Jan, 2012 06:20 PM

Comments

zovirax
zovirax
29 Jan, 2012 01:45 PM

http://www.metro-nica.com buy cheap zovirax zovirax buy zovirax eye ointment zovirax buy zovirax us

Sepmummaetema
Sepmummaetema
02 Feb, 2012 09:25 PM

Hi! my name is Jully. I would like to meemeet seemly urchin :)
This is my homepage - http://jskdh5jkd7djh4.com/l

joirlopergo
joirlopergo
12 Feb, 2012 05:12 AM

Hello! vwatch movie.

Xanax Drugstore
Xanax Drugstore
18 Feb, 2012 02:14 PM

zolpidem bula order zolpidem http://zolpidemdrugstore.com/ zolpidem online prescription ambien

Ruytujuiyy
Ruytujuiyy
02 Mar, 2012 09:18 PM

Блок-контейнеры различных типов и назначений, модульные здания.Металические ограждения,сварные балки,колонны. Фермы для кровли.Разработка КМ,КМД.Изготовление по чертежам заказчика.Обработка грунт,эмаль, цинкование.Изготовление строительных конструкций (колонны, фермы ,ограждающие конструкции)как для промышленного так и для гражданского строительства и сельского хозяйства http://www.metalkompozit.ru металлокаркас ремонт холодильников

Valium
Valium
05 Mar, 2012 08:32 AM

buy cheap diazepam pills fast delivery order diazepam online side effects http://diazepamrxph.com/ buy diazepam online

Ambien
Ambien
05 Mar, 2012 05:33 PM

using buy ambien generic ambien market http://ambienyes.com buy ambien online without a rx does generic ambien work treatment of insomnia and ambien buy lorazepam

No new comments are allowed on this post.

Hosting provided by http://www.DiscountASP.NET