Tuesday, 26 July 2011

HTML Agility Pack breaks XHTML

We have some HTML that contains the tag <br /> but when we parse this through the HTML Agility Pack to process the HTML, it converts it to <br>.

The solution to this the following:

var doc = new HtmlDocument();
HtmlNode.ElementsFlags["br"] = HtmlElementFlag.Empty;
doc.OptionWriteEmptyNodes = true;

doc.LoadHtml(html);
//process data
return doc.DocumentNode.OuterHtml;


More can be found on this StackOverflow post

Thursday, 14 July 2011

Compression support not configured

A colleague and I were having to debug an issue with the Lucene search engine. When trying to index data we kept receiving the following error.

Compression support not configured

Further details and the solution is avaliable on my colleagues blog.

Wednesday, 23 March 2011

MCPD ASP.NET Developer 3.5

Yesterday I successfully passed the upgrade MCPD exam 70-567. Not a great pass mark, but still managed the pass. The result pays off for all that studying that had to been done.

Monday, 21 February 2011

Cannot resolve the collation conflict

I've been working recently on databases that contain different collations. Mainly the following two:
  • SQL_Latin1_General_CP1_CI_AS
  • Latin1_General_CI_AS
When trying to write simple queries I kept getting the following error:

Cannot resolve the collation conflict between "SQL_Latin1_General_CP1_CI_AS" and "Latin1_General_CI_AS" in the equal to operation.

To solve this you just need to cast the field to the correct collatiion using COLLATE Latin1_General_CI_AS
Example.

SELECT *
FROM Table1INNER JOIN Table2

ON Table1.ID = Table2.ID
WHERE Table1.ID = 1


This would become

SELECT *
FROM Table1INNER JOIN Table2

ON Table1.ID COLLATE Latin1_General_CI_AS = Table2.ID
WHERE Table1.ID = 1

Friday, 4 February 2011

Blank or Empty lists for Windows Features

I've seen this issue a few times where the "Turn Windows features on or off" window is empty, stopping you from installing or uninstalling a feature.

Microsoft's solution is to perform a "System Restore" which is quite a drastic action.

There is a more viable fix for this issue available here:
FIX Blank or Empty List in Vista Turn Windows Features On or Off (OptionalFeatures.exe)

Tuesday, 21 December 2010

Server.MapPath when HttpContext is null

I've been writing some code that is fired from a scheduled task and need to access the root of a website. The usual method of Server.MapPath() returns an error as the HttpContext is null due to running under another thread.
To work around this problem you can use the method:
System.Web.Hosting.HostingEnvironment.MapPath()

Monday, 20 December 2010

Images showing in Firefox but not IE

I've worked on a site recently when images would show up in Firefox but not IE. This is an issue with IE not being able to show images that have the colour mode set to CMYK.

To solve, change all the image colour modes to RGB.

  1. Open the image in Photoshop
  2. Select the Image menu
  3. Select the Mode menu
  4. Select the mode you want
  5. Save image

Wednesday, 1 December 2010

Run program as Administrator from search box

If you type in the search box, you can find and run an application you are after, example notepad. If you click enter once the application is highlighted, this will run the application as a normal user.

To get the program to open as an administrator user, use the following short cut:

Ctrl + Shift + Enter

Tuesday, 30 November 2010

MSBuild and recursive copying

If you require to copy files and folder recursively, you'll need to use the following code.

First declare the list of files to copy in an ItemGroup

<ItemGroup>
  <Files Include=".\**\*.cs" />
</ItemGroup>

Then use the files metadata to perform the copy.

<copy DestinationFiles="@(Files)->'location\%(RecursiveDir)%(Filename)%(Extension)')" SourceFiles="@(Files)" />

More information available at MSBuild Team Blog article

MSBuild updating TeamCity build status

If you are using TeamCity and MSBuild to provide Continuous Integration and are using custom build tasks, you can get MSBuild to update the status of the build in TeamCity.

You need to add the following line:

<Message Importance="high" Text="##teamcity[progressMessage 'Packaging media files ...']" />