Quick way to check .NET Framework version in Powershell

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse |
Get-ItemProperty -name Version,Release -EA 0 |
Where { $_.PSChildName -match '^[^0-9S]'} |
Select PSChildName, Version, Release, @{
switch -regex ($_.Release) {
    "378389" { [Version]"4.5" }
    "378675|378758" { [Version]"4.5.1" }
    "379893" { [Version]"4.5.2" }
    "393295|393297" { [Version]"4.6" }
    "394254|394271" { [Version]"4.6.1" }
    "394802|394806" { [Version]"4.6.2" }
    {$_ -gt 394806} { [Version]"Undocumented 4.6.2 or higher, please update script" }

Very useful tip to check .Net Framework version:

Run above commands in Windows Powershell to get .Net version currently installed in your windows.

Powershell check .Net Framework version

Powershell check .Net Framework version


Debug Dataset error

I got this error:

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

With the debug tricks from PaulStock, that helps!

References: http://stackoverflow.com/questions/7026566/failed-to-enable-constraints-one-or-more-rows-contain-values-violating-non-null


2013 in review

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 3,700 times in 2013. If it were a NYC subway train, it would take about 3 trips to carry that many people.

Click here to see the complete report.



Happy New Year 2014, of course!!



Filter by Comma Separated Values in IN Clause ?

The Customer table has ‘PrimaryCode’ and ‘OtherCode’ columns store Code from Codes table:Image

However some of the codes store in Customer table do not exist in Codes table.

I need to let Codes table left join Customer table, this is the first version SQL:

select * from Codes a
left outer join Customer b
on a.CodeID in (b.PrimaryCode)

That did not give me the correct outcome as query above miss out the values in OtherCodes column, so I try this:

select * from Codes a
 left outer join Customer b
 on a.CodeID in (CAST(b.PrimaryCode as varchar) + ',' + b.OtherCodes)

I try to concat the PrimaryCode + OtherCodes to have a clause like this: IN(‘1,2,3,4,5’), but that does not seems right, and I get the error message:

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value ‘23,24,26,27’ to data type int.

Ok, now I know that is not right doing that, there are few solutions provided in internet (search from Google of course!). The final solution would be using LIKE keyword, then I have this which work perfect:

select * from Codes a
left outer join Customer b
on ',' + Cast(b.PrimaryCode as varchar) + ',' + b.OtherCodes + ',' LIKE '%,' + Cast(a.CodeID as varchar) + ',%'

The result I want:



Hints to search in Google: Comma separated values in IN Clause

Keywords: LIKE

Reference: http://stackoverflow.com/questions/4613273/sql-use-comma-separated-values-with-in-clause

IIS Handler for Custom Url

Recently need to setup environment for bug fix.

The client side code calling url like http://somewhere/upload/, while at the server side the url need to receives the POST request from client to perform certain actions.

We have the ready client code to send the POST request with the contents, the missing part is the receiving side, the url in server. Current code will always give us error whenever calls made to the url because the url does not exists at all. My mission today will be faking a url to receives request and output the content as a new file, so we can test the bug fix later on.

Client code: (Refer to Posting multipart/form-data Using .NET WebRequest)

private string ExecutePostRequest(
Uri url,
Dictionary<string, string> postData,
string fileMimeType
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url.AbsoluteUri);
request.Method = "POST";
request.KeepAlive = false;
string boundary = "ILikeSeperator";
request.ContentType = "multipart/form-data; boundary=" + boundary;
request.Credentials = CredentialCache.DefaultCredentials;

// Connect to server and start sending data (use POST)
Stream requestStream = request.GetRequestStream();
postData.WriteMultipartFormData(requestStream, boundary);

byte[] endBytes = System.Text.Encoding.UTF8.GetBytes("--" + boundary + "--");
requestStream.Write(endBytes, 0, endBytes.Length);

// Get back response from server
using (WebResponse response = request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
return reader.ReadToEnd();

Nothing much to say about the client code 😀

Server Code: (My works here)

The url I going to creates is http://localhost/uploadTest. We need to add a ashx handler in IIS to handle the calls into this url. The handler will create a new text file base on contents sent by client.

There are total 6 steps needed and the sequence numbers will be highlight in Bold + red colour = Number

~~~ 0 ~~~ 0 ~~~

1- First follow the must read step-by-step guides on creating handler for specific url – ASP.NET ASHX Handler

Project created follow above guide, removed unnecessary .aspx and files.

Aspx Handler Project

2- Another important step, use correct Web.config:-

<?xml version="1.0"?>
For more information on how to configure your ASP.NET application, please visit
<customErrors mode="Off"/>
<urlMappings enabled="true">
<add url="~/Default.aspx" mappedUrl="~/FileUploadHandler.ashx"/>
<compilation debug="true"/>
<remove name="WebDAVModule"/>
<handlers accessPolicy="Read, Write, Execute, Script">
<remove name="StaticFile"/>
<remove name="SimpleHandlerFactory-ISAPI-2.0"/>
<remove name="WebDAV"/>
<remove name="SimpleHandlerFactory-Integrated-4.0"/>
<remove name="SimpleHandlerFactory-Integrated"/>
<add name="SimpleHandlerFactory-Integrated" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode"/>
<add name="SimpleHandlerFactory-Integrated-4.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" type="System.Web.UI.SimpleHandlerFactory" resourceType="Unspecified" requireAccess="Write" preCondition="integratedMode,runtimeVersionv4.0"/>
<add name="SimpleHandlerFactory-ISAPI-2.0" path="*.ashx" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv2.0,bitness32" responseBufferLimit="0"/>
<add name="StaticFile" path="*" verb="GET,HEAD,POST,DEBUG,PUT,DELETE" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Read"/>
<remove users="*" roles="" verbs=""/>
<add accessType="Allow" users="*" verbs="GET,HEAD,POST,PUT,DELETE,DEBUG"/>

3- The core of the handler code inside FileUploadHandler.ashx:

public void ProcessRequest(HttpContext context)
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");

// Read input
string requestContent = new StreamReader(context.Request.InputStream).ReadToEnd();
if (string.IsNullOrWhiteSpace(requestContent))

string[] requestArray = requestContent.Split(new[] { "--ILikeSeperator" }, StringSplitOptions.RemoveEmptyEntries);

if (requestArray.Count() > 0)
string fileContent = GetContent(requestArray[0]);

if (!string.IsNullOrWhiteSpace(fileContent))
// Send back response to client

// Create upload file

4 – IIS Setup: Add new application, use default authentication

Ashx IIS Setup

5 – Deploy the Ashx handler to upload directory (Created from AspxHandler project).

Remember use Web.config given above.


6 – Set folder permission in uploadTest directory. Allow write permission for IIS_IUSRS (This is built-in IIS user) so handler able to create new folder and files.


You will get errors in client and server if no write permission is allow in mapped directory of the url:

Client error:

System.Net.WebException was unhandled
  Message=The remote server returned an error: (500) Internal Server Error.

Error in client code

Server Error:

System.UnauthorizedAccessException was unhandled by user code
  Message=Access to the path ‘C:\inetpub\wwwroot\uploadTest\MyUploadContents\’ is denied.

Error in Server code


Enjoy your customize handler just for the url you want!

Next post will talks about the debugging in ashx handler, a simple and short article 😉

Sample source code:



Customize url handler, file upload handler, file upload ashx, iis handler, HttpWebRequest


WPF Performance – General

Deal with Performance in WPF applications

This article tells the basic thread structure of WPF (which I thinks is important for me right now as I need to know that for the WPF performance tuning), some tricks and basic concepts of WPF design.

Good article (I said that because probably I can understand them now after some time :P, also if the article can explain in more simpler way when compare to Microsoft documents)

Try to follow WPF design concept to have a best performance (MVVM, Display UI on the fly,…)

Next post will be some technical findings when I works on WPF performance.

夜再微笑 :)

不知不觉四年了,微笑的夜 再次微笑 🙂

原本天气预报今天 17/Mar/2013 大约两点午后会下雨,可是我的运气真的不错,老天爷也特别眷顾我,两点后竟然太阳高挂,顿时让我的行程宽裕了很多,让我今天的的风车之游更加惬意。

7.2xpm 在 Schiphol 机场,排着队要上楼梯进飞机前,抬头望下天空,竟然看到 4 年前的笑容高挂夜空!嗯~~这次没人可以分享,还是离队拿相机拍下来先,下次给朋友看。


回到 Cardiff 后,夜依然晴朗,她依然微笑。



恰巧三天后是第一次 International Day of Happiness, 不过我也不想说是天上的祝福之类的,人类还没有伟大到一个小节日也可以得到上天的祝福。


Smiley night sky captured at Amsterdam Schiphol airport on 17-Mar-2013 7.2xpm

Smiley Night Sky again



Reference: 微笑的夜

Keywords: smile, smiley night sky again.








距 36 天后再吃到华人餐,牛腩饭。

2013-2-19 (Tue)