SharePoint 2010 Twitter Web Part

17 Jan

It’s been a while time since my last post here.Today I’m going to talk about Building Twitter web part in SharePoint 2010 as seen below.


Note:Before you start you can download code from here ( Please do not forget to rate it)

SharePoint 2010 Twitter Web Part

SharePoint 2010 Twitter Web Part Features

  • Allow you to display Profile or search with include replies and include retweets when you select Profile mode
  • you can specify numbers of tweets or status(1,2,..etc)
  • The Status will be updated during specific time(10,15,30,45,16) asynchronously (no need to refresh page).
  • It’s Free Open-mouthed smile

Twitter Web Parts important things to know

1- Define and pass custom parameters to Visual web part.

if you look to the following image you will see that I’m using custom properties to initialize web part,this is easy in normal web part but not in visual web part


To get rid this issue you need to follow this steps

  • Open your web part class that inherits from ASP,Net WebPart class
  • Add custom properties let say Profile
public class TwitterWepPart : WebPart
public enum TwitterMode
[Description("Select a category from the dropdown list.")]
[WebDisplayName("Twitter Mode")]
[Category("Twitter Settings")]
public TwitterMode Mode



as you can see I’m using Enum to display the value in DropDown List

  • After Defining the whole custom properties you need to define a property of TwitterWebPart in user control
public partial class TwitterWepPartUserControl : UserControl

public TwitterWepPart PropertiesWebPart;


  • The final step is to pass the custom properties within CreateChildControls method
public class TwitterWepPart : WebPart


// Visual Studio might automatically update this path when you change the Visual Web Part project item.
private const string _ascxPath = @"~/_CONTROLTEMPLATES/SPTwitter/TwitterWebPart/TwitterWebPartUserControl.ascx";

protected override void CreateChildControls()
TwitterWebPartUserControl control = Page.LoadControl(_ascxPath) as TwitterWebPartUserControl;
control.PropertiesWebPart = this;




As you can see  Page.LoadControl is used to load the control of type Control but in our case we want LoadControl to return TwitterWebUserControl instead of Control,so we can read the values of Custom Properties of this web part from usercontrol.

var Tweets = GetProfile(PropertiesWebPart.Name, PropertiesWebPart.Count, PropertiesWebPart.Retweet, PropertiesWebPart.Replies);

We are able now read value from Custom Properties like count,including Retweets ..etc,

2- Using Twitter API to display the results

For user Mode you need to pass the following parameters to twitter

  • User name with or without @
  • Number of status to display
  • Include Replies (optional)
  • Include Retweets (Optional)

you will then Create Get request as following

For Search Mode you only need the following Parameters

  • Search Name
  • Number of status to display

The request will be like this

Start working on web part

1- Open the project on Visual studio 2010 –>Deploy

Note:You need to change Site Url before deploy web part.

2- Open your site then add web part to the page.

3- Click on Edit Web Part and go to Twitter Settings Section


Let us select Profile as Twitter Mode and in the name let us type Dr oz account @DrOz and Count will be 3.

Click ok to close web part panel and save the page then you will find the following results


Now Let us change the mode to Search and select SharePoint 2010 as a name of this Search.



I hope you like this web part and really appreciate your comments and feedback



Posted by on January 17, 2012 in SharePoint


Tags: , , , ,

13 responses to “SharePoint 2010 Twitter Web Part

  1. mmzimam

    January 17, 2012 at 4:33 pm

    great article and what a coincidence, I was trying something similar. Guess what, I got what I wanted. Thanks Ahmed, you’re always such a great helper in SharePoint.

    • Ahmed Naji

      January 17, 2012 at 5:57 pm

      I hope you like it ,really
      All best wishes to you my dear brother.

  2. Jagan

    January 31, 2012 at 10:46 pm

    Thank you brother……you made my day….

  3. Ahmed Naji

    February 1, 2012 at 5:43 am

    Glad you like it.

  4. Nitin Gupta

    February 6, 2012 at 10:10 am

    Are you looking to show the twitter updates of your organization on your sharepoint portal ? If yes, then this project is what you might need.

    We are providing five !webparts for SharePoint 2007 & SharePoint 2010.
    1.First, that can be used to show the tweets of any user on the SharePoint portal.
    2.Second webpart can be used to post tweet to twitter directly from your sharepoint portal.
    3.Third webpart can be used to show the friends of any user on the SharePoint portal.
    4.Fourth webpart can be used to show the followers of any user on the SharePoint portal.
    5.Fifth webpart can be used to show the ‘follow us’ link, which lets the user follow with a single click.
    Just download and install, and you are all set.

    • Ahmed Naji

      February 6, 2012 at 11:23 am

      Amazing ..
      Thanks 4 sharing

  5. TSG

    April 26, 2012 at 9:27 am

  6. Anshuman

    August 6, 2012 at 9:30 am

    I am getting a 401 error in the code… can you please suggest why it might be happening? it is for search condition

    • Ahmed Naji

      August 6, 2012 at 10:22 am

      I guess this is an issue related to twitter web service itself.Anyway I will check it and let you know.

  7. Anshuman

    August 6, 2012 at 10:28 am

    that will great, I am able to browse the URL in browser but return XDocument.Load(url) this line is throwing me a 401 error.

  8. Anurag

    November 11, 2012 at 6:21 pm

    hi i can not undestant from where to write the code as i am very new to sharepoint sevelopment.and the link also not displaying the code.pls suggest


    January 25, 2013 at 6:47 am

    “SharePoint 2010 Twitter Web Part DotNet Finder” was
    in fact a really wonderful article, . Continue
    composing and I will keep reading! Thanks for your effort ,Frederick

  10. Krista

    March 1, 2013 at 10:19 pm

    Thank you for using time in order to publish “SharePoint 2010 Twitter Web Part | DotNet Finder” jarronegro .
    Thank you yet again ,Sherlene


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: