Tuesday, 13 July 2010

I use Posterous for publishing photographs online. I like the easy posting by email, the maps for geotagged photos and the integration with Twitter, Facebook, Flickr etc. If, like me, you use ASP.NET for your website, here's a little function to get the lastest photos from your Posterous feed.



Share this webpage Comments on this webpage

Friday, 4 December 2009

From my latest Google Analytics figures, 52% of the visitors to this website are from outside the UK. I decided to put Google Adsense on my blog posts as I wanted to show relevant ads and take advantage of it's geo-targeting features, so, for example, a visitor from Germany would see German adverts. I decided the best place for the ads is in the 'related posts' box below each blog article. As related posts are rendered from code behind by a custom control, it's not as simple as just pasting in the Google Adsense code. So, here's the trick to add Adsense, or anything else you want, to the related posts control.



Share this webpage Comments on this webpage

Monday, 23 November 2009

IntenseDebate is a great free blog comments system. Here's a bit of LINQ to XML VB.NET code that will get posts from your blog that have recent comments. IntenseDebate offer a JavaScript version that will show the most popular posts over all time, but the problem with this is that it's not very customisable, doesn't allow for any ASP.NET caching and if a post gets a lot more comments than any others then it will always be at the top of the list, ignoring more recent post comments.



Share this webpage Comments on this webpage

Thursday, 8 October 2009

So, you've got two great things, the IntenseDebate commenting software and the BlogEngine.NET blogging software, and you want to combine them to make something greater than the sum of its parts. Here's how it's done.

  1. Pop over to IntenseDebate and get the JavaScript code they provide.
  2. Open up the file 'post.aspx', which is in the root folder of your blog.
  3. Disable the built in commenting system by setting the 'CommentView' usercontrol to 'visible = false' like so;

    <uc:CommentView ID="CommentView1" runat="server" Visible="false" />

  4. Paste the IntenseDebate code below the disabled usercontrol, wrapping it in an 'If' statement so the code is only rendered if comments are enabled for the post;

<% if (Post.IsCommentsEnabled)
{ %>

       <script language="javascript" type="text/javascript">
     var idcomments_acct = 'YOUR ACCOUNT';
var idcomments_post_id;
var idcomments_post_url;
</script>

<script type='text/javascript' src='http://www.intensedebate.com/js/genericCommentWrapperV2.js'></script>

  <% } %>

Voila! An ASP.NET powered blog with a web 2.0 commenting system.

 



Share this webpage Comments on this webpage

Thursday, 25 June 2009

In ASP.NET 3.5 a GridView has built in paging, which is nice, and a DataList has a RepeatColumns property so you can display data in columns as well as rows. But, wouldn't it be cool to have a databound control that has both features? Well, you can.

To turn something that looks like this:

1
2
3
4
5
6
7
8
9
Next >

..into something that looks like this:

1 2 3
4 5 6
7 8 9
Next >

..use a GridView and a bit of code behind.



Share this webpage Comments on this webpage

Thursday, 21 May 2009

For my new 'live' section of my website I decided to use Google Calendar to manage the events and ASP.NET with LINQ to XML to display the events on my site. Getting the right syntax turned out to be a bit tricky, so here's some code that I came up with that should do the trick:

Dim myDT As New DateTime()
myDT = Now

Dim strStartTime As String = ""
Dim strEndTime As String = ""

strEndTime = Left(myDT.AddMonths(12).ToString("s"), 10)
strStartTime = Left(myDT.AddMonths(-1).ToString("s"), 10) 




Share this webpage Comments on this webpage

Monday, 20 April 2009

The blog system I'm using has a Twitter widget that can be added to pages to show your latest tweets. I wasn't quite happy with it so here's a simple Twitter status ASP.NET user control that I put together using LINQ to XML and VB.NET.

The control gets the two latest tweets and caches them for 60 seconds. Just change the .Take(2) line in the LINQ if you want more or less tweets and the OutputCache tag if you want more or less caching. There's a VB.NET function to add hyperlinks to URLs and usernames and a Javascript function to format the time of tweets.

Here's the .ascx file:



Share this webpage Comments on this webpage