Wednesday, June 30, 2010

Web designers, stop using splash ads!!!

Have you visited websites and got really annoyed by ads that span almost the whole page and flash suddenly out of nowhere, blocking you from doing anything meaningful on the page? If so, then welcome to the club – the club of disgruntled web users who get frustrated day in day out by such ads (sometimes called splash ads). But surprisingly, many web designers seem completely oblivious to their agony and keep using these ads on the home pages of their websites. Even hugely popular websites like Espnstar (see screenshot below), Cricinfo and Times of India, to name a few, are resorting to the use of these kind of ads.

Espnstar splash ad

I find ads in general to be obtrusive and irritating but as long as they are in the corner of the page and do not hinder your interactions with the “useful” elements on the page, they are bearable. But splash ads go a step further and make it impossible to use the site as long as they are in view. And as can be expected, the “close” button to get rid of this ad is so miniscule and well camouflaged that you will have to strain your eyes to spot it. I have been visiting Espnstar quite frequently these days thanks to the sports bonanza, what with Football world cup, Wimbledon, Natwest series and Formula 1 all happening simultaneously. But my experience on the site has been pretty frustrating thanks to these ads. I hope the web designers out there are listening to this feedback and stop using such ads soon.

Monday, June 7, 2010

Merging and Centering Excel cells from C# using Office Interop

Many a times, we need to generate Excel reports as output from Windows applications. There are now 2 ways to do this:

To be clear, Open XML is the recommended approach for working with Office applications using .Net. However, there are still many systems that rely heavily on Interop for this so in this post, I will be talking using the Interop approach to work with Excel. Specifically, let’s look at how we can merge a collection of cells and center them through .Net.

To accomplish this, we need to perform 3 steps, and they are as easy as they come – each step requires a single line of code in C#. So let’s take a look at the steps involved:

  • Get an Excel range – For folks familiar with Excel interop, they would be aware that for most operations we would need to get our hands on an Excel Range object and then perform the intended operation on the range. Here is how we can create a Range object

Microsoft.Office.Interop.Excel.Range range = excelApp.get_Range(sheet.Cells[startRowIndex, startColumnIndex], sheet.Cells[endRowIndex, endColumnIndex]);

Here, excelApp refers to an instance of Microsoft.Office.Interop.Excel.Application class. The parameters that we need to pass to the get_Range() specify where we want the range to start and where it should end.

  • Merge the cells – Once we have the handle to the range, we can call the Merge() on the range to do just that – merge the cells that form the range into a single cell

(Warning – there might be data loss if multiple cells within the range have different values)

range.Merge(Type.Missing);

  • Center the cells – Finally, we need to set the alignment of the data in the merged cells so that data appears centered horizontally. This can be done again with a single statement as shown below

range.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

So there you have it, we can put these 3 steps into a method and use it whenever we want to merge and center cells. One more thing we need to do is add a reference to Microsoft.Office.Interop.Excel.dll and import the same DLL to be able to use the Excel Interop API.

Sunday, June 6, 2010

How to make your Windows form appear “Always on Top”

Most of us would have seen and used the Task Manager which is an integral part of Windows. One key behavior exhibited by the task manager is that if its “Always on top” option is turned on, the window will remain open even if focus is moved to another window. So suppose you have notepad and task manager open and the Always on top option is turned on. Now, even if you have set the focus inside notepad and are able to type in notepad, the foreground form will still appear to be Task manager. It makes sense to have this option in applications like Task manager. For example, suppose you want to see the spikes in memory usage or network bandwidth in real time as you use a particular application. It will be easy to have the application open and use it while Task manager is on top so that the changes are visible in real time. In general, this behavior would seem appropriate for many applications that provide system level information in real time.

Having said that, usage of this option can also make sense for user applications, especially for applications which provide some features that work across multiple other applications. For example, I was recently developing an application that provides a history feature in the Windows clipboard (by default Windows clipboard allows a single item to be maintained on the clipboard so this tool was designed to have multiple items on the clipboard and allow pasting of any item from within those) and works across all Windows applications. I felt it would be great to have the Always on top kind of functionality in the form for this application since it would let users always see what is there in the clipboard currently thereby letting him choose the right text/image to paste. As it turns out, enabling this behavior for your applications is really easy if you are using .Net. All you need to do is set the property named TopMost to True for the form that you want to always appear on top. Something like,

mainForm.TopMost = true;




.Net and hence, Windows will handle the rest of the stuff for you; you don’t need to do anything else. Isn’t that really easy? I guess that’s the power that frameworks make available to developers and help in improving their productivity.

Problem with SSL in SQL Reporting Services

When you do a fresh install of the SQL Server, you get an option to install and configure or only install Reporting Services along with the Database engine. If you choose the install and configure option, the Report Server and Report Manager websites will be created and configured for you by the wizard itself (along with a bunch of other stuff like the databases used by Reporting Services). However, it seems the wizard configures the websites to use SSL and when you try to browse the websites using the default URLs – http://localhost/reports and http://localhost/reportserver, you get this error:

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

Digging deeper, if we look at the RSReportServer.config file which we can find in <installation directory>:\Program Files\Microsoft SQL Server\MSRS10_50.MSSQLSERVER\Reporting Services\ReportServer (this is the location for SQL 2008 R2, for SQL 2008 the folder name should be MSRS10.MSSQLSERVER) , we can find the configuration setting which causes this. Within the <configuration> node, there should be an element as below,

<Add Key="SecureConnectionLevel" Value="2"/>





The value of the SecureConnectionLevel setting can vary from 0-3, with a higher value indicating a greater level of security. In order to avoid using SSL, we need to change the value to 0. After changing this value and saving the config file, if we try hitting the Report manager or Report server site, it should start working. One surprising thing that I found was that there was no way (at least I couldn’t find one) to change this setting from the Reporting Services Configuration Manager. Even though we can add/remove the certificates which will be used by SSL, even if we delete all certificates from the configuration manager, it still doesn’t stop using SSL. But hopefully this post will help you to change it from the config file and get rid of the error.

Tuesday, April 13, 2010

Powerful Disk management features in Windows 7

As you all might have read or heard, Visual Studio’s latest version has been shipped – VS 2010. So I decided to get rid of Visual Studio 2008 from my machine and install the latest (and greatest) version. Unfortunately, I didn’t have enough space in my hard disc for installing it – there was 6 GB free space only in my OS drive (C drive) and Visual Studio 2010 Ultimate needs 6GB of space for itself. However, I had lots of free space in the other drives so I was wondering if somehow I could magically extend the OS drive by borrowing space from the other drives. Enter Windows 7 disk management.

To start using the built in disk management utility in Windows 7, just type “disk management” in the start box and click on the “Create and format hard disk partitions” link which should appear almost instantaneously. The start menu should look something like below.

image

The disk management UI is fairly intuitive and shows information about the drives on your hard disc in a tabular as well as graphical format. This is what it showed for my machine.

image

As we can see, there are 3 drives as well as a system partition of 300MB. This snapshot shows information after I extended the drive:). The C: drive was only 40 GB earlier. So let me mention the steps that I followed to extend C: from 40GB to 60GB by taking 20GB from D: drive.

  1. Backup data from D: - I copied the data to E: since I had a lot of free space in that drive
  2. Delete the D: - We need to do this to make the space available for use in another drive. To delete the drive, right click on it in the graph and select “Delete Volume”
  3. Extend C: – To do this, right click on the C drive in the graph and select “Extend Volume”. A wizard will open up asking for the amount of space you want to add to the existing space in the drive. Enter an appropriate amount of space and complete the wizard to extend the volume
  4. Recreate D: – Right click in the unallocated space between C: and E: and select the option to create a new Simple volume. Use all the space available when prompted to enter the space to be used for the drive and complete the wizard.

NOTE: In case the UI shows “At risk” for any of the drives, it will not allow the volume extension. In this case, click on Action –> Rescan disks from the menu to refresh the drive information. This should hopefully resolve the “At risk” errors, unless there is something seriously wrong with your disc :)

I really loved the disk management utility shipped with Windows and hopefully, this post will help highlight how easy yet powerful this utility really is. Hope this also helps you in resolving similar space crunch issues.

Monday, April 12, 2010

Having the right mindset when using a TO DO list

Many of us use To Do lists to keep track of our immediate and future tasks, some maintain it more religiously than others; some rely on it much more than others. Generalizing, To Do lists are known to be a good practice to follow and provides many benefits, some of which being:

  • Provides clarity on how much workload you are under and should expect in the near future
  • Streamline your activities and reduce randomization
  • Can also be used to act as a repository of completed tasks which can be useful when you are trying to review the work you have done with your manager
  • Allows prioritization of work

Given all these benefits that To Do lists provide, there seems a compelling reason to maintain them. There are also plenty of articles, like this one, available on the Internet providing suggestions on how to get the best out of using them. However, I would also like to highlight some traps that one may risk falling into when using these lists.

  • Overreliance on To Do lists : Once you start using to do lists, you can end up feeling the need to put the smallest of tasks that you need to complete in this list. The problem with this approach is, after a period of time, you might start losing confidence in your own memory and feel that you absolutely need to enter the tasks in the list in order to be able to remember them
  • Fiddling with the list too frequently : Another habit that some people develop is to be obsessed with their lists and reviewing it every hour and making unnecessary changes. This is quite obviously not useful since valuable time is wasted in updating the to do list instead of spending it on doing productive work. The ideal way to maintain the list up to date would be to review the list and update, if needed, in the morning – this would give you an idea of what all tasks you need to complete on that day – and reviewing and updating at the end of day – you can mark the completed tasks and add any new ones/change existing ones based on the day’s happenings
  • Incomplete To Do lists : This is arguably much more damaging than being over reliant on the lists. If you are lazy in updating the list, you might miss adding some tasks to the list and since you have the false comfort that there is a To do list, you might not make an effort to remember those tasks. As a result, the task is lost and there is a high likelihood of you missing out on it.

In addition to talking about these pitfalls, I would also like to quote and recommend the strategy that I picked up from a lecture on Time Management by Randy Pausch. According to him, one should break up the To do list into a matrix as below

Important – Due Soon (I) Important – Not Due Soon (II)
Not Important – Due Soon (III) Not Important – Not Due Soon (IV)

* The numbers in the brackets indicate the order in which the quadrants must be visited to pick up new tasks

Essentially, there are 2 columns – tasks can be Due soon or Not due soon; and there are 2 rows – tasks which are Important or Not important. The mistake that most people make, according to Randy, is to take up Unimportant tasks just because they are due soon. The ideal thing to do is to take up and complete ALL Important tasks, ones which are Due soon first and then, the ones which are not due soon. Only if you have no pending important tasks should you take up Unimportant ones. The reasoning being that, when you are working on Important tasks which are not due soon, the Unimportant – Due soon ones can either be discarded (because they are not important) without any problems or they might become important in which case they will move to the first row and can be taken up next. I have been following it religiously ever since I saw his lecture and can vouch for its effectiveness. Hope you find it useful too.

If one manages to avoid falling into the traps I have mentioned above and maintain an accurate but practical to do list, it is bound to prove very useful in managing your time and work. So go ahead and give it a try, trust me, you will be glad you took the plunge.

Friday, April 9, 2010

Blogging v/s Micro blogging – Follow up post

Some time back, I had written about the uptrend in  the number of people turning away from blogging and jumping onto micro blogging in this post. As I mentioned in that post, I feel both these platforms for expressing oneself are going to co-exist in the near future at least. Not only that, we might also see much more integration between the 2 platforms. One such example of combining the power of both these 2 mediums can be seen on a number of popular blogs these days. People nowadays read blog posts and then, spread word about it by talking about the post on their micro blog networks. This is another means of word of mouth publicity. The blog owners, fully aware of this, have started to integrate the comments that people leave on the micro blogs onto their own blogs. So, in effect, anyone who visits the blog now will not only see the comments people have left on that blog itself but also a complete history of what people are saying about that blog post on the micro blogging network. One of the big reasons why this has become possible is also due to the powerful APIs being exposed by micro blogs like Twitter. These APIs allow the consumers to extract exactly the kind of data they are interested in and consume it in any way they want to.

I feel this kind of interaction is only going to grow in the future and this augurs well for us, bloggers and blog readers alike, since we will have better ways to exchange information and knowledge with a larger set of people.