Archive July 2009:
If you've been looking for an ASP.NET Twitter module, look no further. I've coded a C# module in order to consume a given Twitter feed. Download the Twitter module for easy use in your own project.
How to use
You can either show the latest Twitter message or any given number of Twitter messages with this module - all you have to do is to point out a Twitter username and the number of messages to show.
Here's a code example on how you can show 5 Twitter messages in a Repeater.
Code-behind:
string userName = "dileno";
List<TwitterFeed> messages = TwitterFeed.Fetch(userName, 5);
if (messages.Count>0)
{
rptTwitterMessages.DataSource = messages;
rptTwitterMessages.DataBind();
}
Repeater in code-front (aspx/ascx):
<asp:Repeater ID="rptTwitterMessages" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate><li><%#((TwitterFeed)Container.DataItem).Message %> (<a href="<%#((TwitterFeed)Container.DataItem).Link %>"><%#((TwitterFeed)Container.DataItem).PubDate %></a>)</li></ItemTemplate>
</asp:Repeater>
Download the Twitter module
You can download the C# module with complete source code and code examples:
(zip, 16 kB)
Short instructions for implementation
- Drop the TwitterFeed.cs file into your project.
- Use the code in Default.aspx.cs to customize the Twitter messages.
- Update your appSettings.Config with the key TwitterFeedUrl, which you find in this project's appSettings.Config file.
E-mail has become a communication form we can't live without. But e-mail is a killer for productivity - few can argue against that. Here are a few tips that will save you valuable time when dealing with your e-mails.
Don't check your e-mail first in the morning
Whatever you do, don't let your e-mail inbox decide what you should do first in the morning. When you arrive at the office, do your more important tasks first, then check your e-mail.
This will help you to focus on what is really important at the start of the day.
Turn off e-mail notifications
Turn off e-mail notifications if you're serious about productivity. Those notifications will steal the focus from whatever you're doing - and most of the time you don't want that.
This way, you decide when it's time to check your e-mail, and new e-mails wont disturb you while you work on important stuff.
How to turn off e-mail notifications in Outlook 2007
- Go to Tools -> Options.
- Click E-mail Options, choose Advanced E-mail Options.
- Below When new items arrive in my Inbox, untick Display a New Mail Desktop Alert.
I've unticked all boxes here for maximum control:

- Choose Ok for all opened Outlook windows and you'll be fine.
Use e-mail rules
In Outlook, there's a neat function that lets you create e-mail rules, helping you to organize your inbox. You can configure e-mails from a specific person to arrive directly in a folder of your choice, you can directly filter e-mails with attachments, and much more.
I've found e-mail rules particularly good when used to file e-mails. You setup a set of rules and then e-mails are filed under any given folder, so you don't have to do the archiving yourself. Definitely a time saver.
In Outlook 2007, you can configure your e-mail rules under Tools -> Rules and Alerts.
How to setup a simple e-mail filing rule in Outlook 2007
This is how you configure a rule to automatically file e-mails from a specific person, under a specific folder (Outlook 2007).
- Go to Tools -> Rules and Alerts.
- Choose New Rule. Below Stay Organized, choose Move message from someone to a folder. Click Next.
- In the second box, click people or distribution list and choose a contact of your choice. Also, click specified to specify a folder where an e-mail from this contact should be archived. Click next.

- In this step, you'll have a chance to review the rule and change it if you like. Just click Finish when your done!
You'll see all your e-mail rules under Rules and alerts, where you also can manage all rules.
Shut down your e-mail client for a while
In order to be able to focus on any important task, the best way to do this is to shut down your e-mail client. Period.
You'll get more done, I promise you. If you want to send an e-mail, just write this e-mail in Notepad and save it until later. Just keep your e-mail client shut down for a while.
You might also want to consider scheduling your e-mail time, maybe check the e-mail in the morning and in the afternoon. Then you can focus on work in between. And remember - don't check your e-mail the first thing you do in the morning!
Keep it simple
Remember, keep your e-mails simple and to the point. This will not only help you, but your contacts too.
Good e-mail management will help you save time. In the end, you'll get to focus on more important things than e-mail at work and in life.
By following a set of rules, you can improve your CSS skills. Here are five of my quick tips on how you can write better CSS.
Use the cascade
When writing your CSS, make sure you make the best use of the cascade. A lot of classes and id attributes aren’t necessary for HTML elements in order to style them with CSS.
Look at this HTML code example:
<div id="header">
<h1 id="topheading">An awesome CSS example</h1>
<p id="headerintro">Lorem ipsum dolor...</p>
</div>
CSS for the HTML above could look like this:
#header { background: #f1f1f1 }
#topheading { font-size: 2em; font-weight: normal }
#headerintro { font-size: 0.9em; font-weight: bold }
Not only is the HTML code bloated with unnecessary id attributes, but the cascade in CSS isn’t particularly well used.
How you can use the cascade
#header { background: #f1f1f1 }
#header h1 { font-size: 2em; font-weight: normal }
#header p { font-size: 0.9em; font-weight: bold }
By using this CSS code, all id attributes and classes can be removed from the HTML elements inside the header div.
Using the cascade in CSS will save you time and good code will make the job for you.
Sort your properties
You should sort your CSS properties alphabetically. It’s easier to read, easier to maintain and easier to extend CSS rules when the properties are sorted alphabetically.
Try to find a property fast in this rule:
#content {
float: left;
width: 700px;
margin: 10px;
background: #f1f1f1;
padding: 5px
}
It isn't very easy. It's much easier when the properties are sorted.
Alphabetically sorted CSS properties
#content {
background: #f1f1f1;
float: left;
margin: 10px;
padding: 5px;
width: 700px
}
Sorted properties will make it easier for you to find what you are looking for, giving you more time to produce even better code.
Structure properly
You should structure your CSS code properly. Once you’ve come up with a good method to structure your style sheets, stick with this method.
Here’s a simple list on how you can structure your style sheets better:
- Decide how to write your properties – should you put them all on the same line or put each property on a new line?
- Write global styles first. Overall rules for headings, links, forms and similar.
- Structure sections in the order they appear in the HTML code. Example: write CSS rules for the header before the footer and left menu before the content.
- Tab nested rules. It’s always a good idea to use tabs when coding, even style sheets. This is great for readability and works better the larger a style sheet grows.
How you can structure some basic CSS code
body { }
h1,h2,h3 { }
h1 { }
h2 { }
#wrap { }
#header { }
#header #logo { }
#content { }
#leftmenu { }
#maincontent { }
#related { }
#footer { }
Use CSS shorthand
You can minimize your CSS rules by using CSS shorthand. Instead of writing rules like this:
#leftmenu {
background-color: #f1f1f1;
background-image: url(/gfx/bg.png);
background-repeat: no-repeat
background-position: 0 50%;
background-attachment: fixed
}
You can write rules like this:
#leftmenu { background: #f1f1f1 url(/gfx/bg.png) no-repeat 0 50% fixed }
This second shorthand rule is exactly the same as the extended one above.
CSS shorthand can make you more efficient and will make your CSS look better and more organized.
You can use CSS shorthand for background, border and font, amongst other CSS properties.
Dustin Diaz has compiled a great reference on CSS shorthand properties.
Use comments
Comments have several benefits, such as improving the structure. Comments also
- Make it easier to divide your style sheet into specific sections, making the sections easier to find.
- Improve the readability and make the style sheet easier to maintain.
How you can comment your CSS code
/* HEADER */
#header { }
/* CONTENT */
#content { }
/* NAVIGATION */
#leftmenu { }
Choose a coding style and stick to it
It’s important you choose a coding style that suits you and that you stick to it. Maybe you also have more tips to share?
Microsoft's search engine Bing has indeed gained some market share since it went live late this spring. Bing's got its own Webmaster Center where webmasters can use the webmaster tools provided. I'll show you how you can submit your website to Bing's search index.
- Login to WebMaster Center with your Windows Live ID.
- Add your website's web address and the sitemap address (if you have a sitemap XML file):

You can also specify your email address if you want Bing to be able to contact you.
- Authenticate your website ownership through either XML verification or meta tag authentication. You'll have to upload the XML file or any other file to your website.
- Wait for Bing to crawl your website.
Until then, your site summary will look like this:

It might take a couple of days for Bing to add your website to its index. Just remember to be patient and you should be fine!
To be able to focus on what matters the most to you, you can follow a couple of steps that will help you savw time you can spend on what you think is important. Here are five simple steps that will increase your overall productivity.
-
Use a bike
A bike will save you time. Cycling helps you stay fit and healthy. Plus it's environment friendly. A decent bike may not cost more than tickets worthy of 2-3 months of commuting. Saving 20 minutes a day by cycling instead of walking will mean you save 8 hours per month if you use your bike 6 days per week. Don't forget to wear a helmet!
-
Always put your gear at the same place
By always putting your gear at the same place, you won't spend time looking for the gear. You'll instantly know where your gear is and how to get it. Plan where you put accessories like cell phone and wallet. What pocket in your bag? A drawer at work? Know your gear and save time!
-
Remove unnecessary stuff in your home
The more stuff you have at home, the more time you'll have to spend on cleaning and managing all your stuff. This includes furniture, pillows, carpets and similar. By removing the stuff you actually don't need, you will lessen your burden. If you have too much stuff to handle, sell it or give it to charity.
-
Buy quality over quantity
Buying quality probably means more planning and saving money beforehand, but when you've decided for a particular thing to buy, you will certainly not be disappointed. A quality product does its job, works in a way you expect it to work and just fits in. If you buy quantity you'll have to buy more often and you'll have to take care of the stuff you buy. Where should you put all your stuff? What should you do with the old stuff?
Quality products last longer, helping you to focus on what's more important for you.
-
Hire professionals to do it for you
Instead of doing it yourself, you should hire professionals to do craftsmen's work for you. Craftsmen's work might be painting your house, fix your bike, clean your windows and so on. They will do it better and faster than you.
Hiring professionals requires money though. If you don't want to spend all your money on professionals, maybe you know a friend who's a professional and might be able to help you? Maybe you're good at something and can exchange services with your friend? This way, you can build a relationship that will have a positive impact on your productivity and life.
Remember though, it might be better to invest in a professional who's not your friend, than loosing a friend over some lousy conflict.
By following these steps, I promise you'll have more time to do what you think is more important to you. You'll be able to focus on what really matters to you.
Maybe you also have a tip to share for increasing overall productivity?
Thanks to Productivity501 and Unclutterer for inspiring this blog post. You truly rock!
Using different locales
When I developed this blog, I wanted to use the en-GB locale to be able to present correct formats for dates and numbers.
It is simple to set a specific locale for a whole web application - you just have to add the <globalization> tag under <system.web> in Web.Config and set the culture and uiCulture attributes, like this:
<globalization culture="en-gb" uiCulture="en-gb"/>
So far - so good. Dates and numbers have the correct format and everything looks well - until in comes the database.
I use Sweden's best web hosting provider (according to a study published in 2009) and this means the SQL Server database's collation is set to Finnish_Swedish_CI_AS - as it should be.
Having a website and a database with different locales gives you problems. Trust me.
Out-of-range datetime value
The main problem I ran into was a database insert of an incorrect date - the date I tried to insert obviously had an en-GB format while my database expected a date with sv-SE format. This generated an out-of-range datetime value error.
At first, I tried rewriting the date to a correct format, but quickly realized it was wrong to do so. I ended up with one of the two correct solutions for this problem.
Solutions
The two solutions are:
- Update database collation to match your website locale
- Update SQL query to use parameters
I ended up with the latter one - updating my SQL query to use paremeters instead.
This is also how you want to insert and update your database tables - by using parameters with your command object (unless you use any ORM solution like NHibernate, but that's another blog post).
Here's a SQL query where parameters are used (disregard the lousy error handling):
string strSQL = "INSERT INTO mytable(user,password) VALUES(@user,@password)";
SqlConnection objConn = new SqlConnection(connString);
SqlCommand objCmd = new SqlCommand(strSQL, objConn);
objCmd.Parameters.AddWithValue("@user", "username");
objCmd.Parameters.AddWithValue("@password", "secretpassword");
try
{
objConn.Open();
objCmd.ExecuteNonQuery();
}
catch { }
finally
{
objConn.Close();
}
Conclusion
When developing a database driven website, make sure you know the website's locale and the database's collation. Also, use parameters with your SQL queries, not only when dealing with dates and numbers, but always. You don't know what input might try to sneak into the database otherwise.
The DataBinder.Eval method is often used when you want to bind data to a control's template. What DataBinder.Eval really does is to cast Container.DataItem to its specific type, like this:
<%# DataBinder.Eval(Container.DataItem, "Heading") %>
DataBinder.Eval uses .NET reflection in order to cast Container.DataItem to its specific type. The use of reflection in this method will give you a performance loss.
If performance is of importance in your application or if you know what type Container.DataItem is, it's better to use an explicit cast instead:
<%# ((DbDataRecord)Container.DataItem)["Heading"] %>
I hereby want to present this new tech blog for you!
It was time to move on from my swedish blog, and instead focus on blogging in english and using Twitter.
I will post on topics regarding web development, technologies, entrepreneurship, consultant life and what else I find useful and interesting. I will focus on Microsoft technologies such as ASP.NET. I will share my thoughts on web standards and how to use them. I will tell you how you can increase your productivity, and more.
Welcome!