Showing posts from 2015

October Articles

Thank you to all who voted for two of my articles which where listed in top ten on Codeproject. Doing Delegates Differently part 1 and Using HTMLAgility pack and CSS Selectors.

Doing Delegates Differently

This is an article about using delegates in a way in which you may not have thought of using them before. As I started to write this it became obvious that this would be a long article, so I am splitting in two. This first part is an overview of delegates and how to group functionality and cross cutting concerns with them. Part two will delve into using delegates to create a validator which can validate any type of object dynamically. Part 1 - Cross cutting concerns Part 2 - Dynamic Validator
Earlier I wrote that I would include an article for actually getting the data from a web site using mechanisms such as WebClient, HttpWebClient etc. Someone beat me to the punch, go to this well written article in code project. He presents using ScrapySharp. Although I don't have much experience with this product, it looks worth exploring. The article shows how I would use Fidler to examine the requests going back and forth and what needs to be sent as parameters etc. Steve

Using HtmlAgility pack and CssSelectors

To start, I don't claim to be an expert in XPath or Regular Expressions but the following are some observations I have made while parsing HTML documents for client projects. In the following examples I am using HtmlAgility pack (HAP) to load the HTML into a document object model (DOM) and parse into nodes. Additionaly, there are cases where I have had to parse the document on elements which are not truly nodes such as comments. In addition to observations about HAP in general, I’ll point out extension methods provided by HAP.CSSSelectors package which allow for much easier selection. Packages for the example will need to be imported using NuGet. The package descriptions will be loaded in the project but you will need to set NuGet package manager to restore the libraries. In the project I have included a really simple html file with examples of issues I have needed to address in my projects.  To test without any modifications, you will need to copy the HTML file t

Codeproject submission

What I really love about consulting is the variety of projects that come my way. Recently I was asked if we could create an application for a client which allowed them to fill in a PDF and store the data in a database.  I looked around and found several different libraries for dealing with PDF files, I do not mean to say I did an exhaustive search or trial. Almost all these libraries touted their ease of use in creating PDF documents in code, many offered capabilities of reading the documents but almost all of them failed to load a document created with Adobe Acrobat, opening only older unencrypted PDF files. The one exception I found was iTextSharp, a library from  which offers both a commercial version with iText support provided and an open source version available with a copy left AGPL license. Read more at This project explains how to read PDF form fields from a PDF doc