Last week we saw how we can create a Twitter Trends Webpart for SharePoint 2010. Jhonny has developed a Silverlight version of this webpart. He will be posting how he developed the webpart. For the time being enjoy the Twitter Webpart in his blog
Last week we saw how we can create a Twitter Trends Webpart for SharePoint 2010. Jhonny has developed a Silverlight version of this webpart. He will be posting how he developed the webpart. For the time being enjoy the Twitter Webpart in his blog
In this article we will see how we can develop a Twitter Web Part for Sharepoint. We are going to use jQuery and Twitter Search API along with our favorite c# code. The Web Part will be a simple Twitter Widget which will display latest tweets for a Hashtag. Below is a screenshot of how our Web Part will look like.
We are going to name our Web Part Twitter Trends
Lets get started
Fireup Visual Studio 2010 (Oh Yeah we will be using Visual Studio 2010 for our project and you will notice how easy it is for developers to build and deploy SharePoint Projects in VS 2010) and Select File -> New Project and create a new Visual Web Part Project.
Click OK and you will see another Window which will ask you to enter the Local SharePoint site which we will use to Debug our Web Part. Enter your Test Site and Click Finish.
Instead of designing our widget we are going to use the design of a Twitter Widget Tutorial in Tutorialzine.
We will be making few changes in CSS to suit our needs. Please check the above link to learn how the Widget is designed. We will not be discussing what changes were made to the CSS files also download the source code as we will be using CSS Files, Images and Javascript files from that project.
Back to our project in Visual Studio, Right Click our Project and Click Add -> SharePoint “Layouts” Mapped folder.
If you notice, Visual Studio automatically added a folder for us under layouts folder to store our files. Now Create 3 new folders namely CSS, Images, Scripts. Add CSS Files, Images and JS files to these folders.
Now your solution explorer should look like this
Open the ASCX file and add the following code
<link rel="Stylesheet" type="text/css" href="/_layouts/TwitterTrends/css/demo.css" /> <link rel="Stylesheet" type="text/css" href="/_layouts/TwitterTrends/css/jScrollPane.css" /> <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script> <script src="/_layouts/TwitterTrends/scripts/jquery.mousewheel.js" type="text/javascript"></script> <script src="/_layouts/TwitterTrends/scripts/jScrollPane-1.2.3.min.js" type="text/javascript" ></script>
In the above code we have just referenced the proper CSS files and Javascript files including the jQuery file from Microsoft CDN.
Add the below code below the above lines of code. The code is self-explanatory also I have added comments so that it will be easy to understand.
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$('#twitter-ticker').slideDown('slow'); //Slide down the Widget when the page has loaded
RefreshTweets(); //Function which does all the job
setTimeout("RefreshTweets()",60000); //Refresh the Tweets every 1 minute
});
function RefreshTweets() {
var container = $('#tweet-container');
if(hashtag == "") //Global variable declared through C# code
{
hashtag = "SharePoint"; //Set Default Hashtag
}
$.getJSON("http://search.twitter.com/search.json?q=%23" + hashtag + "&rpp=15&&callback=?", function (msg) {
container.html(''); //Remove the Loading GIF
for (i = 0; i < msg.results.length; i++) { //Build DIVs containing Tweets and add it to Container DIV
var str = '<div><div><a href="http://twitter.com/' + msg.results[i].from_user + '" target="_blank"><img src="' + msg.results[i].profile_image_url + '" alt="' + msg.results[i].from_user + '"/></a></div>';
str += '<div><a href="http://twitter.com/' + msg.results[i].from_user + '"target="_blank">' + msg.results[i].from_user + '</a></div>';
str += '<div>' + relativeTime(msg.results[i].created_at) + '</div>';
str += '<div>' + formatTwitString(msg.results[i].text) + '</div>';
container.append(str);
}
});
container.jScrollPane(); //Add Scrollbar
}
We will also be using 2 functions which is used to Format Tweet and Time (you can find this function in script.js which you have downloaded from Tutorialzine website)
function formatTwitString(str)
{
str=' '+str;
str = str.replace(/((ftp|https?):\/\/([-\w\.]+)+(:\d+)?(\/([\w/_\.]*(\?\S+)?)?)?)/gm,'<a href="$1" target="_blank">$1</a>');
str = str.replace(/([^\w])\@([\w\-]+)/gm,'$1@<a href="http://twitter.com/$2" target="_blank">$2</a>');
str = str.replace(/([^\w])\#([\w\-]+)/gm,'$1<a href="http://twitter.com/search?q=%23$2" target="_blank">#$2</a>');
return str;
}
function relativeTime(pastTime)
{
var origStamp = Date.parse(pastTime);
var curDate = new Date();
var currentStamp = curDate.getTime();
var difference = parseInt((currentStamp - origStamp)/1000);
if(difference < 0) return false;
if(difference <= 5) return "Just now";
if(difference <= 20) return "Seconds ago";
if(difference <= 60) return "A minute ago";
if(difference < 3600) return parseInt(difference/60)+" minutes ago";
if(difference <= 1.5*3600) return "One hour ago";
if(difference < 23.5*3600) return Math.round(difference/3600)+" hours ago";
if(difference < 1.5*24*3600) return "One day ago";
var dateArr = pastTime.split(' ');
return dateArr[4].replace(/\:\d+$/,'')+' '+dateArr[2]+' '+dateArr[1]+(dateArr[3]!=curDate.getFullYear()?' '+dateArr[3]:'');
}
</script>
Next, Add the below code which will add the required DIVs and containers
<div id="main"> <div id="twitter-ticker"> <div id="top-bar"> <div id="twitIcon"><img src="/_layouts/TwitterTrends/images/twitter_64.png" width="64" height="64" alt="Twitter"/></div> <h2>Twitter Trends</h2> </div> <div id="tweet-container"><img id="loading" src="/_layouts/TwitterTrends/images/loading.gif" width="16" height="11" alt="Loading.." /></div> <div id="scroll"></div> </div> </div>
Now it’s time to add our Custom Property to the Web Part so that users will be able to enter their own hashtag.
Open VisualWebpart1.cs and change
[ToolboxItemAttribute(false)] to [ToolboxItemAttribute(true)]
Add the below code which will add a Textbox under a custom category.
[WebBrowsable(true),
Category("Twitter Trends"),
Personalizable(PersonalizationScope.User),
DefaultValue(""),
WebDisplayName("Hash Tag"),
WebDescription("Please enter a hashtag")]
public string TwitterTrendsProperty
{
get { return HashTag; }
set { HashTag = value; }
}
public static string HashTag;
Next, Open the code behind file for the user control which will show the Tweets and add the below code under Page Load event.
string strHashTag;
strHashTag = VisualWebPart1.HashTag;
Response.Write("<input type='hidden' value='" + strHashTag + "' id='hashtag'/>");
ClientScriptManager cs = Page.ClientScript;
cs.RegisterClientScriptBlock(GetType(), "hashtag", "<script>var hashtag='" + strHashTag + "';</script>");
In the above code we declare a new Javascript variable and set its value based on the Value entered in our custom property “Hashtag”
That’s it! Now it’s time to test our Twitter Trends Web Part
Right click the project and select Deploy. Yes it is that simple!
Wait for Visual Studio to deploy the solution. You should see the status in the status bar
To test our new Web Part, open the site and add the Web Part. You should find your webpart under “Custom” Category.
After adding the Web Part, Click “Edit Webpart” to enter your own hastag and see our new Twitter Web Part in action
Download : Twitter Trends [Source Code] Twitter Trends [WSP]
Its time to announce the Winners for our Microsoft Visual Studio 2010 with MSDN Giveaway. Initially we planned to announce the Winners on 20th July but we had a tough time selecting the winners because of 60+ wonderful entries.
To make it fair I requested my friend Victor Gaudioso to choose the winners. Here is a brief summary about him
Victor, a Microsoft Most Valuable Professional (MVP) and Microsoft Solutions Advocate is an independent Windows Presentation Foundation / Silverlight / Windows 7 Mobile / Surface developer, instructor (classroom / video tutorials / written articles), published author (Foundation Blend 2: Building Applications in WPF and Silverlight (2008), Foundation Blend 3 with Silverlight (2009)), and public speaker.
Victor has over 10 years experience in the web and software development industries and has worked with large Fortune 500 companies such as Microsoft, Universal, Warner Bros., Disney, Mattel, and Paramount Pictures. Victor has worked on some of the most cutting edge WPF and Silverlight applications that have been developed to date; including the Microsoft Surface Winebar CES demo , Surface Air Hockey with simulated physics, and the Surface EventPhotos application which both debuted at PDC in 2008. Victor was also part of the team that launched the Microsoft Silverlight Entertainment Tonight Emmy mini-site, one of the very first Silverlight applications to market. He is also a Microsoft MVP
You can follow him in Twitter @victorgaudioso
where he tweets about Silverlight, WPF etc
Now here are the Winners for our Giveaway
Congratulations to the Winner and I will be contacting them via email. Thank you everyone who participated and this is our first giveaway in allaboutmoss and we hope to giveaway more in the future.
Update: Winners announced, please check : http://www.allaboutmoss.com/index.php/2010/07/23/microsoft-visual-studio-2010-with-msdn-winners/
Here is your chance to Win Microsoft Visual Studio 2010 Ultimate with MSDN subscription which is worth $11,899. We have two copies to give away for our wonderful readers

How can I win?
Simple! All you have to do is follow these simple steps
Contest closes on July 17th and Winners will be announced on July 20th.
You can learn more about Visual Studio 2010 here.
SharePoint 2010 is available in 2 versions namely Standard and Enterprise. If you have installed a standard version and want to convert to Enterprise features then you can simply change the license type by
Looks Simple.. But wait, Do you see the Textbox disabled?
There is another way to change License type from Standard CAL to Enterprise CAL.
Keep in mind there is no turning back here. Once you upgrade to Enterprise version you cannot switch back to Standard version.
Unlike other development technologies SharePoint development may be a costly affair. We need a Windows Server OS if we are developing for MOSS 2007.
Things are getting better with SharePoint 2010 and you can install MOSS 2010 in a Windows 7 pc and start developing apps but what if you don’t have a good build or required software?
Virtual labs for SharePoint 2010 are here. You can test drive SharePoint 2010 without any instalation.
Virtual labs for Developers cover the following
IT Pro labs are available in TechNet.
New SharePoint 2010 Exams Available in July
Announcing the availability in July 2010 of four new SharePoint 2010 exams:
In this article we will see how we can to get data from a content editor webpart from one page and display it in another page using a custom webpart.
If you are new to webpart development you can check out my previous post about Hello world SharePoint Web Part for Beginners
Add the following code in the RenderWebPartmethod of the webpart you are creating. The code and comments are self explanatory. Please pose a comment if you have any problem in understanding the code.
SPSite site = new SPSite("http://mysite">http://mysite"); // create object of the site
SPWeb web;
Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager mgr = null;
web = site.OpenWeb();
mgr = web.GetLimitedWebPartManager("Pages/mypage.aspx", System.Web.UI.WebControls.WebParts.PersonalizationScope.User);//http://mysite/Pages/mypage.aspx will be the URL of the source page
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in mgr.WebParts)
{
if (wp.Title == "My RichTextEditor") //My RichTextEditor is the webpart title
{
SPWebPartPages.ContentEditorWebPart webPart = (SPWebPartPages.ContentEditorWebPart)wp;
output.Write(webPart.Content.InnerText);
}
}
This is one of the ‘not so common’ but confusing error. All of a sudden multiple documents upload will not work and give you the following error.
Can not run Windows SharePoint Services on the Page
There are different possible reasons for this error.
1.
2.
It is normally not advisable to edit upload.aspx file in the layouts folder but there may be cases when you have to edit this file. One thing which you should keep in mind is updates like Service Pack will overwrite thee files so try the following.
Steps
1. Backup upload.aspx and then Open upload.aspx and search for
<input TYPE="hidden" NAME="_charset_" VALUE="utf-8
2. Update the following string as follows
<input TYPE="hidden" NAME="Cmd" VALUE="Save
3. Save your file.
4. Reset IIS and try to upload multiple files in document library.
Recent Comments