About 15 months ago I bought a new Dell Studio 17; with the added options is cost me around $3,500. I thought I paid extra for an additional 12 month warranty on top of the standard 12 months but when I rang recently to get a faulty hard drive replaced it turned out my warranty had expired.
The guy on the phone went through to sales to get me a quote for a new 12 month warranty. He came back with a “discounted” price of $700, with some sales spiel about how with this warranty my “hard drive problem would definately be rectified”. When I told him that was ridiculous and that I could fix it myself he backtracked and said they could get the price down as that cost included all sorts of other crap I didn’t ask for… not so much Mr Dell.
I ended up buying a new 500GB 7,200rpm Seagate drive for around $100, swapping it over myself in about 5 minutes, then used Acronis Home to image my failing drive onto the new one to avoid having to reinstall everything (which I doubt Dell would have done).
It irritates me that Dell try this kind of BS as people who don’t know better would just pay. I guess the fact that I also bought a Dell Netbook just a couple of months ago doesn’t count for anything either.
JSON doesn’t have a standard way to represent a date. You can read about the reasons behind this here.
If you are using an ASMX web service returning JSON then you’ll find it serializes the DateTime object to a string that looks like this:
var dateString = "/Date(1278943200000)/";
var date = new Date(parseInt(dateString.replace(/\/Date\((\d+)\)\//, '$1')));
In the above example I’ve manually set the date string, but you may get this from an AJAX response from the ASMX web service. I then create a new Date object by using the regular expression and parsing the result at an integer.
Here’s a quick an easy way to show the time difference between two DateTime objects using C#.
The DateTime structure has an overridden subtract operator which return a TimeSpan object when subtracting two DateTimes:
public static TimeSpan operator -(DateTime d1, DateTime d2);
You can then use this TimeSpan to get the amount of time between each DateTime:
DateTime fromDate = DateTime.Now.AddDays(-1).AddMinutes(-10).AddSeconds(-20);
DateTime toDate = DateTime.Now;
TimeSpan timeSpan = toDate - fromDate;
string timeString =
(timeSpan.Days * 24) + timeSpan.Hours,
In the above example I’m comparing a date in the past to the current date. This could be useful for working out the total amount of time that has passed since something has happened.
I’m then using the Hours, Minutes and Seconds properties of the TimeSpan to format a string displaying the amount of time. If the hours goes over 24 then the Days property is used, so for my hours I’m also adding on the number of days multiplied by 24.
Today I needed to convert a comma separated string of numbers in an integer array. Here is how you can do it in one line using Linq:
string csv = "1,1,2,3,5,8,13,21,34";
int numbers = csv.Split(',').Select(n => int.Parse(n)).ToArray();
Recently I had a problem where I added a Visual Studio Test Project to a solution.
As part of our CI, the build server failed to build as it didn’t contain the necessary files for the test framework. One option would have been to install Visual Studio Team System on the build server, but it seems a bit crazy to do that just to get the tests to build.
I found a post here by Mark Kharitonov that explains a method to get tests building without having to install Visual Studio which worked perfectly for me.
Web Camps is free so there is no excuse not to go…
When creating web applications with ASP.NET developers will usually create User Controls or Custom Server Controls. User Controls have the ASCX extension and allow developers to group together ASP.NET controls and functionality into a reusable control. Custom Controls are a bit more complex and require the developer to define the html that the control generates as well as all it’s functionality. It is also possible to add child ASP.NET controls to a Server Control and have the control render those child control and maintain their viewstate with little work.
In .NET 2.0 the abstract CompositeControl class was introduced, which is derived from WebControl but also uses the interfaces INamingContainer, which makes sure all child controls have a unique ID, and ICompositeControlDesignerAccessor which is used to allow the control to render the control automatically at design time based on the child controls. The CompositeControl also ensures that child controls are always created which saves using the EnsureChildControls method that many Custom Control developers will be familiar with.
In this post I’ll explain how to create a simple Composite Custom Control and how to customise the HTML that it renders.
I came across a situation where I needed to make sure at least one checkbox in an ASP.NET CheckBoxList is checked before submitting the page. Looking at the source each checkbox element created shares the same client ID with a different number at the end, so I needed a way to select all checkboxes where the ID started the same.
In this post I’ll explain how to populate a select dropdownlist using jQuery and Ajax. I am using an ASP.NET web application and page methods to perform the Ajax calls. Using page methods means that you do not need a seperate web service, which is good if the functionality is specifically for the page. The page methods must be declared public static and use the WebMethod attribute.
In this post I’ll show how to use jQuery to automatically convert all email addesses from static text into a mailto link.