Tagc#

NVelocity template with decimal to two decimal places

N

I wanted to be able to output a decimal value from an object in my NVelocity template. For example, the value of the decimal was: 3.40000 to represent 3.4. The end result: Total Order Value: 3.40 GBP I needed to display this as currency format. Sure, I could of used this String.Format method, but that adds £ or $ or whatever (depending on your environment setup) to the start of the resulting...

C# Ternary conditional operator – Question mark in an if statement

C

I’m all for shortening the amount of code we write, if it makes it more readable. One enhancement I make use of in C# is the ternary conditional operator. Consider the following block of code: string input = "hi"; bool saidHello; if (input = "hello") { saidHello = true; } else { saidHello = false; } In this example, we can see, the saidHello boolean value would be false,  as the input string...

JoeBlogs – Typo in dummy URL fixed

J

I’ve recently had a few comments that the JoeBlogs wrapper wasn’t working – and they were getting an “invalid response” or more specifically “Response XML not valid XML-RPC – missing methodResponse element.” It seems that I had a typo in my comments in JoeBlogs.TestHarness/Program.cs on line 15: //typically (if your wordpress blog is installed in root dir) The problem, is the xmlprc.php – this...

Reverse GeoCoding with Google API and C#

R

I needed to write a function to get a set of co-ordinates from an address, supplied as a string. Using the Google API, I came up with this: First, I created a struct, to represent the lat and lon co-ordinates: public struct Coordinate { private double _latitude; private double _longitude; public Coordinate(double latitude, double longitude) { _latitude = latitude; _longitude = longitude; } public...

Using JoeBlogs -metaWeblog API Wrapper

U

Step 1 Download the latest release of JoeBlogs from Codeplex (Click the Downloads tab, and select the latest download) Step 2 Unzip the contents of the downloaded zip file. (I usually copy DLLs I am going to use into a “lib” folder at the root of my solution) Step 3 Add a reference to BOTH CookComputing.XmlRpcV2.dll AND JoeBlogs.dll Include AlexJamesBrown.JoeBlogs in your class, with using /...